In [1]:
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import datetime
from datetime import date
import seaborn as sns
import warnings
warnings.filterwarnings('ignore')
In [2]:
# Read MA PPE data
df = pd.read_csv('MA_ppe_regions.csv', parse_dates=['Time'])
df.drop(['Total Persons Tested','Percent Positivity','Deaths','Hospitalized Total', 'Hospitalized ICU'], axis=1, inplace=True)
df = df.loc[df['Region']!='State Agency'].dropna(how='all')
df
Out[2]:
Time Region N95s/KN95s Masks Gowns Gloves Ventilators Confirmed Cases
0 2020-04-29 Central Massachusetts 138350.0 263767.0 43293.0 454250.0 79.0 5363.0
1 2020-04-30 Central Massachusetts 146820.0 269267.0 43573.0 457450.0 79.0 NaN
2 2020-05-01 Central Massachusetts 157800.0 276767.0 43838.0 472050.0 79.0 NaN
3 2020-05-02 Central Massachusetts 161960.0 277517.0 44658.0 480450.0 79.0 NaN
4 2020-05-03 Central Massachusetts 161960.0 277517.0 44658.0 480450.0 79.0 NaN
... ... ... ... ... ... ... ... ...
347 2020-08-12 Massachusetts 10476785.0 11665045.0 736612.0 10116833.0 679.0 113198.0
348 2020-08-19 Massachusetts 11161755.0 12488545.0 742512.0 10422377.0 679.0 115048.0
349 2020-08-26 Massachusetts 11192185.0 12525245.0 747887.0 10502349.0 679.0 117085.0
350 2020-09-02 Massachusetts 11194995.0 12544695.0 752587.0 10527949.0 679.0 119426.0
351 2020-09-09 Massachusetts 11206955.0 12547295.0 756087.0 10546549.0 679.0 121396.0

308 rows × 8 columns

Note:

This notebook is generalized in three parts for each region to analyze PPE distribution vs confirmed cases.

1: Figures of absolue value of cumulative PPE data vs cumulative confirmed cases data.

2: Figures of ratios of PPE data to confirmed cases. (See comments for 6 different ratios)

3: Figures of regression and results.







Summary

1: This data set is from DPH and MEMA. The PPEs are distributed to those who will have a supply shortage within the next 5 days and are not able to sourcethe material through their normal supply chain. This data set may not show the entire pucture of PPE supply in Mass.

2: At first, Feds gave Mass. the least amount of PPE but sent large shipments to states with smaller population and far few cases. (https://www.wbur.org/news/2020/07/23/fema-masks-ppe-massachusetts-coronavirus)

3: There is a huge increase on July 22 for N95s/KN95s which may be caused by large supplys from FEMA.(Not sure)

5: There is a linear relationship between cumulative gowns/gloves and cumulative confirmed cases based on the data we have. If we ignore the data from 7/22/2020, the relationship also exists between cumulative N95s/KN95s/Masks and cumulative confirmed cases.

...







PPE Distribution vs Confirmed Cases

Southeastern Massachusetts

In [3]:
SM = df.loc[df['Region']=='Southeastern Massachusetts']
SM_CC = SM.dropna()
categories = ['N95s/KN95s', 'Masks', 'Gowns', 'Gloves', 'Ventilators']
for category in categories:
    SM_CC['{} %'.format(category)] = SM_CC[category]/SM_CC[category].iloc[-1] * 100
    
fig, axes = plt.subplots(2, 3, figsize=(25,15))
for ax, category in zip(axes.flatten(), categories):
    sns.distplot(SM_CC[category].diff(), ax=ax)
    ax.set_xlabel(category, fontsize=15)
fig.delaxes(axes[1,2])
SM_CC
Out[3]:
Time Region N95s/KN95s Masks Gowns Gloves Ventilators Confirmed Cases N95s/KN95s % Masks % Gowns % Gloves % Ventilators %
176 2020-04-29 Southeastern Massachusetts 234696.000 408835.0 66317.0 686220.0 79.0 9446.0 17.127662 21.662026 42.409224 40.099902 100.0
183 2020-05-06 Southeastern Massachusetts 271607.000 494885.0 80542.0 853420.0 79.0 11616.0 19.821356 26.221365 51.506005 49.870389 100.0
190 2020-05-13 Southeastern Massachusetts 294853.000 579135.0 93570.0 1020308.0 79.0 13243.0 21.517804 30.685331 59.837313 59.622644 100.0
197 2020-05-20 Southeastern Massachusetts 306789.000 610735.0 101149.0 1111008.0 79.0 14953.0 22.388871 32.359650 64.684027 64.922783 100.0
204 2020-05-27 Southeastern Massachusetts 354094.000 643835.0 121174.0 1198208.0 79.0 16026.0 25.841098 34.113446 77.489864 70.018396 100.0
205 2020-06-03 Southeastern Massachusetts 371135.000 674335.0 127784.0 1338408.0 79.0 16832.0 27.084718 35.729481 81.716909 78.211113 100.0
206 2020-06-10 Southeastern Massachusetts 377062.000 691835.0 131684.0 1369208.0 79.0 17297.0 27.517259 36.656714 84.210930 80.010939 100.0
207 2020-06-17 Southeastern Massachusetts 378627.000 697785.0 134614.0 1370008.0 79.0 17597.0 27.631469 36.971974 86.084643 80.057688 100.0
208 2020-06-24 Southeastern Massachusetts 381785.000 705885.0 138104.0 1436408.0 79.0 17770.0 27.861934 37.401150 88.316472 83.937834 100.0
209 2020-07-01 Southeastern Massachusetts 383545.000 705885.0 139104.0 1453608.0 79.0 17965.0 27.990376 37.401150 88.955965 84.942931 100.0
210 2020-07-08 Southeastern Massachusetts 388295.000 713385.0 140304.0 1471908.0 79.0 18123.0 28.337021 37.798536 89.723356 86.012309 100.0
211 2020-07-15 Southeastern Massachusetts 402660.000 755335.0 145104.0 1519908.0 79.0 18280.0 29.385352 40.021247 92.792920 88.817233 100.0
212 2020-07-22 Southeastern Massachusetts 627550.000 1085285.0 146004.0 1536908.0 79.0 18501.0 45.797391 57.503570 93.368463 89.810644 100.0
213 2020-07-29 Southeastern Massachusetts 845815.000 1336835.0 149674.0 1572708.0 79.0 18803.0 61.725950 70.831887 95.715400 91.902650 100.0
214 2020-08-05 Southeastern Massachusetts 957085.000 1467935.0 151024.0 1596908.0 79.0 19143.0 69.846221 77.778190 96.578715 93.316800 100.0
215 2020-08-12 Southeastern Massachusetts 1273785.000 1783185.0 151924.0 1607908.0 79.0 19411.0 92.958377 94.481637 97.154258 93.959595 100.0
216 2020-08-19 Southeastern Massachusetts 1363775.000 1880035.0 152574.0 1665676.0 79.0 19648.0 99.525674 99.613211 97.569929 97.335322 100.0
217 2020-08-26 Southeastern Massachusetts 1369645.000 1885135.0 155474.0 1695476.0 79.0 19904.0 99.954055 99.883434 99.424457 99.076712 100.0
218 2020-09-02 Southeastern Massachusetts 1369795.000 1887235.0 155474.0 1703276.0 79.0 20316.0 99.965002 99.994702 99.424457 99.532513 100.0
219 2020-09-09 Southeastern Massachusetts 1370274.573 1887335.0 156374.0 1711276.0 79.0 20666.0 100.000000 100.000000 100.000000 100.000000 100.0

Distplot of PPE Growth

In [4]:
# Confirmed cases vs PPE distribution
fig, axes = plt.subplots(2,1,figsize=(15,14))

percentages = ['N95s/KN95s %', 'Masks %', 'Gowns %', 'Gloves %', 'Ventilators %']

for category in categories:
    axes[0].plot('Time', category, data=SM_CC, marker='.', markersize=10)

axes[0].set_xlabel('Date', fontsize=15)
axes[0].set_ylabel('The Number of PPE Distribution', fontsize=15)
axes[0].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020, 9,9)])
axes[0].tick_params(direction='out', length=6, width=2, labelsize=10)
axes[0].legend()
axes[0].set_title('PPE Distribution vs Confirmed Cases in SM', fontsize=20)

ax1 = axes[0].twinx()
ax1.plot('Time', 'Confirmed Cases', data=SM_CC, color='y', linestyle='--', linewidth=3, label='Confirmed Cases')

ax1.set_ylabel('Confirmed Cases', fontsize=15)
ax1.tick_params(direction='out', length=6, width=2, labelsize=10)
ax1.legend(loc='upper right')


for percentage in percentages:
    axes[1].plot('Time', percentage, data=SM_CC, marker='.', markersize=10)

axes[1].set_xlabel('Date', fontsize=15)
axes[1].set_ylabel('PPE Distribution %', fontsize=15)
axes[1].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020, 9,9)])
axes[1].tick_params(direction='out', length=6, width=2, labelsize=10)
axes[1].legend()
axes[1].set_title('PPE Distribution Percentage vs Confirmed Cases in SM', fontsize=20)

ax2 = axes[1].twinx()
ax2.plot('Time', 'Confirmed Cases', data=SM_CC, color='y', linestyle='--', linewidth=3, label='Confirmed Cases')

ax2.set_ylabel('Confirmed Cases', fontsize=15)
ax2.tick_params(direction='out', length=6, width=2, labelsize=10)
ax2.legend(loc='upper right')

plt.show()
In [5]:
pd.set_option("display.max_rows", None, "display.max_columns", None)


# Calculate the ratio of cumulative PPE data to cumulative confirmed cases data (Ratio 1)
for category in categories:
    SM_CC['{} Ratio 1'.format(category)] = SM_CC[category]/SM_CC['Confirmed Cases']
    
    
    
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 2)
# (Interval=2 weeks, one week before + the week itself)
SM_CC['Confirmed Cases(ma1)'] = SM_CC['Confirmed Cases'].rolling(window=2,center=False).mean()
SM_CC.iloc[0,-1] = (6065 + 9446) / 2
for category in categories:
    SM_CC['{} Ratio 2'.format(category)] = SM_CC[category]/SM_CC['Confirmed Cases(ma1)']





# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 3)
# (Interval=2 weeks, one week after + the week itself)
SM_CC['Confirmed Cases(ma2)'] = SM_CC['Confirmed Cases'].rolling(window=2,center=False).mean().shift(-1)
for category in categories:
    SM_CC['{} Ratio 3'.format(category)] = SM_CC[category]/SM_CC['Confirmed Cases(ma2)']

    
    
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 4)
# (Interval=3 weeks, one week before + one week after + the week itself)
SM_CC['Confirmed Cases(ma3)'] = SM_CC['Confirmed Cases'].rolling(window=3,center=False).mean().shift(-1)
SM_CC.iloc[0,-1] = (6065+9446+11616)/3
for category in categories:
    SM_CC['{} Ratio 4'.format(category)] = SM_CC[category]/SM_CC['Confirmed Cases(ma3)']

    
    
# Calculate the ratio of delta PPE data to delta confirmed cases data (Ratio 5)
for category in categories:
    SM_CC['{} Ratio 5'.format(category)] = SM_CC[category].diff()/SM_CC['Confirmed Cases'].diff()
    
    
    
# Calculate the ratio of delta PPE data to moving average delta confirmed cases data (Ratio 6)
for category in categories:
    SM_CC['{} Ratio 6'.format(category)] = SM_CC[category].diff()/SM_CC['Confirmed Cases'].diff().rolling(window=2,center=False).mean()
# SM_CC
In [6]:
# Plot the Ratio of PPE to Confirmed Cases

RATIO1 = []
RATIO2 = []
RATIO3 = []
RATIO4 = []
RATIO5 = []
RATIO6 = []
RATIOS = [RATIO1, RATIO2, RATIO3, RATIO4, RATIO5, RATIO6]
for RATIO in RATIOS:
    for category in categories:
        RATIO.append('{} Ratio {}'.format(category, RATIOS.index(RATIO)+1))

fig, ax = plt.subplots(1,1,figsize=(14, 6))
color = ['b', 'g', 'r', 'c', 'm']

for category in categories:
    ax.plot('Time', category, data=SM_CC, color=color[categories.index(category)], linewidth=3, label=category, marker='.', markersize=12)
    ax.set_xlabel('Date', fontsize=15)
    ax.set_ylabel('The number of PPE', fontsize=15)
    ax.set_xlim([datetime.date(2020, 4, 29), datetime.date(2020, 9,9)])
    ax.legend(loc='best')
    ax.set_title('The Ratio of PPE Dstribution to Confirmed Cases in Southeastern Massachusetts', fontsize=20)
ax1 = ax.twinx()
for ratio in RATIO1:
    ax1.plot('Time', ratio, data=SM_CC, color=color[RATIO1.index(ratio)], linestyle='--', linewidth=3, label=ratio, marker='^', markersize=8)
    ax1.set_ylabel('Ratio', fontsize=15)
    ax1.legend(loc='best')
plt.show()

         
         
fig, axes = plt.subplots(6,1,figsize=(15,48))
color = ['b', 'g', 'r', 'c', 'm']

for RATIO in RATIOS:
    for category in categories:
        axes[RATIOS.index(RATIO)].plot('Time', category, data=SM_CC, color=color[categories.index(category)], linewidth=3, label=category, marker='.', markersize=12)
        axes[RATIOS.index(RATIO)].set_xlabel('Date', fontsize=15)
        axes[RATIOS.index(RATIO)].set_ylabel('The number of PPE', fontsize=15)
        axes[RATIOS.index(RATIO)].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
        axes[RATIOS.index(RATIO)].legend(loc='best')
        axes[RATIOS.index(RATIO)].set_title('The Ratio of PPE Dstribution to Confirmed Cases in Southeastern Massachusetts', fontsize=20)
    ax1 = axes[RATIOS.index(RATIO)].twinx()
    for ratio in RATIO:
        ax1.plot('Time', ratio, data=SM_CC, color=color[RATIO.index(ratio)], linestyle='--', linewidth=3, label=ratio, marker='^', markersize=8)
        ax1.set_ylabel('Ratio', fontsize=15)
        ax1.legend(loc='best')
plt.show()
In [7]:
for category in categories:
    SM_CC['{} delta'.format(category)] = SM_CC[category].diff()
    SM_CC['Confirmed Cases delta'] = SM_CC['Confirmed Cases'].diff()

fig, axes = plt.subplots(2, 3, figsize=(29,15))

for ax, category in zip(axes.flatten(), categories):
    sns.regplot('Confirmed Cases', category, data=SM_CC, ax=ax)
    ax.set_xlabel('Confirmed Cases', fontsize=20)
    ax.set_ylabel(category, fontsize=20)
    ax.tick_params(direction='out', length=6, width=2, labelsize=12)
fig.delaxes(axes[1,2])
fig.suptitle('Regression Plot for Southeastern Massachusetts(Cumulative vs Cumulative)', fontsize=30)

fig1, axes1 = plt.subplots(2, 3, figsize=(25,15))

for ax, category in zip(axes1.flatten(), categories):
    sns.regplot('Confirmed Cases delta', category + ' delta', data=SM_CC, ax=ax)
    ax.set_xlabel('Confirmed Cases', fontsize=15)
    ax.set_ylabel(category, fontsize=15)
fig1.delaxes(axes1[1,2])
fig1.suptitle('Regression Plot(delta vs delta)', fontsize=25)
Out[7]:
Text(0.5, 0.98, 'Regression Plot(delta vs delta)')
In [8]:
# Regression Analysis
import statsmodels.api as sm

Y = [pd.DataFrame] * 5
X = [pd.DataFrame] * 5
for category in categories:
    Y[categories.index(category)] = SM_CC[category]
    X[categories.index(category)] = SM_CC['Confirmed Cases']
    X[categories.index(category)] = sm.add_constant(X[categories.index(category)])
    model = sm.OLS(Y[categories.index(category)], X[categories.index(category)])
    results = model.fit()
    print(results.summary())
                            OLS Regression Results                            
==============================================================================
Dep. Variable:             N95s/KN95s   R-squared:                       0.507
Model:                            OLS   Adj. R-squared:                  0.480
Method:                 Least Squares   F-statistic:                     18.51
Date:                Sun, 13 Sep 2020   Prob (F-statistic):           0.000429
Time:                        20:58:00   Log-Likelihood:                -280.81
No. Observations:                  20   AIC:                             565.6
Df Residuals:                      18   BIC:                             567.6
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const           -1.186e+06   4.36e+05     -2.718      0.014    -2.1e+06   -2.69e+05
Confirmed Cases   107.1923     24.913      4.303      0.000      54.851     159.533
==============================================================================
Omnibus:                        9.838   Durbin-Watson:                   0.150
Prob(Omnibus):                  0.007   Jarque-Bera (JB):                2.154
Skew:                           0.214   Prob(JB):                        0.341
Kurtosis:                       1.450   Cond. No.                     1.07e+05
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 1.07e+05. This might indicate that there are
strong multicollinearity or other numerical problems.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:                  Masks   R-squared:                       0.564
Model:                            OLS   Adj. R-squared:                  0.540
Method:                 Least Squares   F-statistic:                     23.30
Date:                Sun, 13 Sep 2020   Prob (F-statistic):           0.000135
Time:                        20:58:00   Log-Likelihood:                -283.86
No. Observations:                  20   AIC:                             571.7
Df Residuals:                      18   BIC:                             573.7
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const           -1.374e+06   5.08e+05     -2.705      0.015   -2.44e+06   -3.07e+05
Confirmed Cases   139.9880     29.004      4.827      0.000      79.053     200.923
==============================================================================
Omnibus:                       10.775   Durbin-Watson:                   0.146
Prob(Omnibus):                  0.005   Jarque-Bera (JB):                2.120
Skew:                           0.100   Prob(JB):                        0.346
Kurtosis:                       1.418   Cond. No.                     1.07e+05
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 1.07e+05. This might indicate that there are
strong multicollinearity or other numerical problems.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:                  Gowns   R-squared:                       0.983
Model:                            OLS   Adj. R-squared:                  0.982
Method:                 Least Squares   F-statistic:                     1024.
Date:                Sun, 13 Sep 2020   Prob (F-statistic):           2.57e-17
Time:                        20:58:00   Log-Likelihood:                -190.91
No. Observations:                  20   AIC:                             385.8
Df Residuals:                      18   BIC:                             387.8
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const           -2.182e+04   4870.244     -4.480      0.000   -3.21e+04   -1.16e+04
Confirmed Cases     8.8974      0.278     31.995      0.000       8.313       9.482
==============================================================================
Omnibus:                       10.626   Durbin-Watson:                   1.050
Prob(Omnibus):                  0.005   Jarque-Bera (JB):                8.090
Skew:                          -1.269   Prob(JB):                       0.0175
Kurtosis:                       4.809   Cond. No.                     1.07e+05
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 1.07e+05. This might indicate that there are
strong multicollinearity or other numerical problems.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:                 Gloves   R-squared:                       0.986
Model:                            OLS   Adj. R-squared:                  0.985
Method:                 Least Squares   F-statistic:                     1224.
Date:                Sun, 13 Sep 2020   Prob (F-statistic):           5.28e-18
Time:                        20:58:00   Log-Likelihood:                -236.99
No. Observations:                  20   AIC:                             478.0
Df Residuals:                      18   BIC:                             480.0
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const           -2.868e+05   4.88e+04     -5.882      0.000   -3.89e+05   -1.84e+05
Confirmed Cases    97.3975      2.784     34.982      0.000      91.548     103.247
==============================================================================
Omnibus:                        1.993   Durbin-Watson:                   0.861
Prob(Omnibus):                  0.369   Jarque-Bera (JB):                1.440
Skew:                          -0.643   Prob(JB):                        0.487
Kurtosis:                       2.724   Cond. No.                     1.07e+05
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 1.07e+05. This might indicate that there are
strong multicollinearity or other numerical problems.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:            Ventilators   R-squared:                        -inf
Model:                            OLS   Adj. R-squared:                   -inf
Method:                 Least Squares   F-statistic:                    -18.00
Date:                Sun, 13 Sep 2020   Prob (F-statistic):               1.00
Time:                        20:58:00   Log-Likelihood:                 612.88
No. Observations:                  20   AIC:                            -1222.
Df Residuals:                      18   BIC:                            -1220.
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const              79.0000   1.71e-14   4.62e+15      0.000      79.000      79.000
Confirmed Cases  3.469e-18   9.77e-19      3.550      0.002    1.42e-18    5.52e-18
==============================================================================
Omnibus:                        5.214   Durbin-Watson:                   0.214
Prob(Omnibus):                  0.074   Jarque-Bera (JB):                3.191
Skew:                           0.940   Prob(JB):                        0.203
Kurtosis:                       3.543   Cond. No.                     1.07e+05
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 1.07e+05. This might indicate that there are
strong multicollinearity or other numerical problems.







Northeastern Massachusetts

Northeastern Massachusetts is the region with the most confirmed cases number.

In [9]:
NM = df.loc[df['Region']=='Northeastern Massachusetts']
NM_CC = NM.dropna()
categories = ['N95s/KN95s', 'Masks', 'Gowns', 'Gloves', 'Ventilators']
for category in categories:
    NM_CC['{} %'.format(category)] = NM_CC[category]/NM_CC[category].iloc[-1] * 100
    
fig, axes = plt.subplots(2, 3, figsize=(25,15))
for ax, category in zip(axes.flatten(), categories):
    sns.distplot(NM_CC[category].diff(), ax=ax)
    ax.set_xlabel(category, fontsize=15)
fig.delaxes(axes[1,2])
NM_CC
Out[9]:
Time Region N95s/KN95s Masks Gowns Gloves Ventilators Confirmed Cases N95s/KN95s % Masks % Gowns % Gloves % Ventilators %
132 2020-04-29 Northeastern Massachusetts 113720.000 226198.0 22974.0 335932.0 117.0 14920.0 8.791882 13.718007 40.468557 42.851093 100.0
139 2020-05-06 Northeastern Massachusetts 144600.000 260413.0 27849.0 427832.0 117.0 18056.0 11.179266 15.793010 49.055839 54.573749 100.0
146 2020-05-13 Northeastern Massachusetts 158983.000 297113.0 32024.0 514032.0 117.0 20158.0 12.291240 18.018719 56.410076 65.569321 100.0
153 2020-05-20 Northeastern Massachusetts 164193.000 320263.0 35174.0 559032.0 117.0 22088.0 12.694034 19.422674 61.958781 71.309468 100.0
160 2020-05-27 Northeastern Massachusetts 186775.000 339663.0 40604.0 614332.0 117.0 23370.0 14.439885 20.599207 71.523692 78.363471 100.0
161 2020-06-03 Northeastern Massachusetts 193712.000 366013.0 42635.0 688832.0 117.0 24334.0 14.976196 22.197229 75.101286 87.866604 100.0
162 2020-06-10 Northeastern Massachusetts 196071.000 375913.0 46315.0 700832.0 117.0 25003.0 15.158575 22.797625 81.583583 89.397310 100.0
163 2020-06-17 Northeastern Massachusetts 198897.000 385913.0 49195.0 703632.0 117.0 25424.0 15.377057 23.404085 86.656685 89.754475 100.0
164 2020-06-24 Northeastern Massachusetts 200936.000 390163.0 50520.0 726632.0 117.0 25734.0 15.534696 23.661831 88.990664 92.688328 100.0
165 2020-07-01 Northeastern Massachusetts 201506.000 391063.0 50870.0 730632.0 117.0 26022.0 15.578764 23.716412 89.607187 93.198563 100.0
166 2020-07-08 Northeastern Massachusetts 202526.000 392663.0 51370.0 731132.0 117.0 26316.0 15.657621 23.813446 90.487934 93.262343 100.0
167 2020-07-15 Northeastern Massachusetts 207526.000 442163.0 52670.0 739632.0 117.0 26659.0 16.044180 26.815423 92.777876 94.346593 100.0
168 2020-07-22 Northeastern Massachusetts 575436.000 857263.0 55670.0 744632.0 117.0 26969.0 44.487913 51.989583 98.062357 94.984387 100.0
169 2020-07-29 Northeastern Massachusetts 876266.000 1225163.0 55820.0 744632.0 117.0 27346.0 67.745580 74.301252 98.326581 94.984387 100.0
170 2020-08-05 Northeastern Massachusetts 891786.000 1242163.0 55920.0 746632.0 117.0 27934.0 68.945457 75.332234 98.502730 95.239504 100.0
171 2020-08-12 Northeastern Massachusetts 1119236.000 1473313.0 56270.0 761992.0 117.0 28416.0 86.529994 89.350560 99.119253 97.198808 100.0
172 2020-08-19 Northeastern Massachusetts 1289776.000 1643613.0 56470.0 771952.0 117.0 28909.0 99.714725 99.678576 99.471552 98.469294 100.0
173 2020-08-26 Northeastern Massachusetts 1292496.000 1643613.0 56720.0 783952.0 117.0 29416.0 99.925012 99.678576 99.911925 100.000000 100.0
174 2020-09-02 Northeastern Massachusetts 1292996.000 1648613.0 56770.0 783952.0 117.0 29972.0 99.963668 99.981806 100.000000 100.000000 100.0
175 2020-09-09 Northeastern Massachusetts 1293465.941 1648913.0 56770.0 783952.0 117.0 30541.0 100.000000 100.000000 100.000000 100.000000 100.0
In [10]:
# Confirmed cases vs PPE distribution
fig, axes = plt.subplots(2,1,figsize=(15,14))

percentages = ['N95s/KN95s %', 'Masks %', 'Gowns %', 'Gloves %', 'Ventilators %']

for category in categories:
    axes[0].plot('Time', category, data=NM_CC, marker='.', markersize=10)

axes[0].set_xlabel('Date', fontsize=15)
axes[0].set_ylabel('The Number of PPE Distribution', fontsize=15)
axes[0].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
axes[0].tick_params(direction='out', length=6, width=2, labelsize=10)
axes[0].legend()
axes[0].set_title('PPE Distribution vs Confirmed Cases in NM', fontsize=20)

ax1 = axes[0].twinx()
ax1.plot('Time', 'Confirmed Cases', data=NM_CC, color='y', linestyle='--', linewidth=3, label='Confirmed Cases')

ax1.set_ylabel('Confirmed Cases', fontsize=15)
ax1.tick_params(direction='out', length=6, width=2, labelsize=10)
ax1.legend(loc='upper right')


for percentage in percentages:
    axes[1].plot('Time', percentage, data=NM_CC, marker='.', markersize=10)

axes[1].set_xlabel('Date', fontsize=15)
axes[1].set_ylabel('PPE Distribution %', fontsize=15)
axes[1].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
axes[1].tick_params(direction='out', length=6, width=2, labelsize=10)
axes[1].legend()
axes[1].set_title('PPE Distribution Percentage vs Confirmed Cases in NM', fontsize=20)

ax2 = axes[1].twinx()
ax2.plot('Time', 'Confirmed Cases', data=NM_CC, color='y', linestyle='--', linewidth=3, label='Confirmed Cases')

ax2.set_ylabel('Confirmed Cases', fontsize=15)
ax2.tick_params(direction='out', length=6, width=2, labelsize=10)
ax2.legend(loc='upper right')

plt.show()
In [11]:
pd.set_option("display.max_rows", None, "display.max_columns", None)


# Calculate the ratio of cumulative PPE data to cumulative confirmed cases data (Ratio 1)
for category in categories:
    NM_CC['{} Ratio 1'.format(category)] = NM_CC[category]/NM_CC['Confirmed Cases']
    
    
    
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 2)
# (Interval=2 weeks, one week before + the week itself)
NM_CC['Confirmed Cases(ma1)'] = NM_CC['Confirmed Cases'].rolling(window=2,center=False).mean()
NM_CC.iloc[0,-1] = (10641+14920) / 2
for category in categories:
    NM_CC['{} Ratio 2'.format(category)] = NM_CC[category]/NM_CC['Confirmed Cases(ma1)']





# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 3)
# (Interval=2 weeks, one week after + the week itself)
NM_CC['Confirmed Cases(ma2)'] = NM_CC['Confirmed Cases'].rolling(window=2,center=False).mean().shift(-1)
for category in categories:
    NM_CC['{} Ratio 3'.format(category)] = NM_CC[category]/NM_CC['Confirmed Cases(ma2)']

    
    
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 4)
# (Interval=3 weeks, one week before + one week after + the week itself)
NM_CC['Confirmed Cases(ma3)'] = NM_CC['Confirmed Cases'].rolling(window=3,center=False).mean().shift(-1)
NM_CC.iloc[0,-1] = (10641+14920+18056)/3
for category in categories:
    NM_CC['{} Ratio 4'.format(category)] = NM_CC[category]/NM_CC['Confirmed Cases(ma3)']

    
    
# Calculate the ratio of delta PPE data to delta confirmed cases data (Ratio 5)
for category in categories:
    NM_CC['{} Ratio 5'.format(category)] = NM_CC[category].diff()/NM_CC['Confirmed Cases'].diff()
    
    
    
# Calculate the ratio of delta PPE data to moving average delta confirmed cases data (Ratio 6)
for category in categories:
    NM_CC['{} Ratio 6'.format(category)] = NM_CC[category].diff()/NM_CC['Confirmed Cases'].diff().rolling(window=2,center=False).mean()
NM_CC
Out[11]:
Time Region N95s/KN95s Masks Gowns Gloves Ventilators Confirmed Cases N95s/KN95s % Masks % Gowns % Gloves % Ventilators % N95s/KN95s Ratio 1 Masks Ratio 1 Gowns Ratio 1 Gloves Ratio 1 Ventilators Ratio 1 Confirmed Cases(ma1) N95s/KN95s Ratio 2 Masks Ratio 2 Gowns Ratio 2 Gloves Ratio 2 Ventilators Ratio 2 Confirmed Cases(ma2) N95s/KN95s Ratio 3 Masks Ratio 3 Gowns Ratio 3 Gloves Ratio 3 Ventilators Ratio 3 Confirmed Cases(ma3) N95s/KN95s Ratio 4 Masks Ratio 4 Gowns Ratio 4 Gloves Ratio 4 Ventilators Ratio 4 N95s/KN95s Ratio 5 Masks Ratio 5 Gowns Ratio 5 Gloves Ratio 5 Ventilators Ratio 5 N95s/KN95s Ratio 6 Masks Ratio 6 Gowns Ratio 6 Gloves Ratio 6 Ventilators Ratio 6
132 2020-04-29 Northeastern Massachusetts 113720.000 226198.0 22974.0 335932.0 117.0 14920.0 8.791882 13.718007 40.468557 42.851093 100.0 7.621984 15.160724 1.539812 22.515550 0.007842 12780.5 8.897930 17.698682 1.797582 26.284731 0.009155 16488.0 6.897137 13.718947 1.393377 20.374333 0.007096 14539.000000 7.821721 15.558016 1.580164 23.105578 0.008047 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
139 2020-05-06 Northeastern Massachusetts 144600.000 260413.0 27849.0 427832.0 117.0 18056.0 11.179266 15.793010 49.055839 54.573749 100.0 8.008418 14.422519 1.542368 23.694728 0.006480 16488.0 8.770015 15.794093 1.689047 25.948083 0.007096 19107.0 7.567907 13.629193 1.457529 22.391375 0.006123 17711.333333 8.164264 14.703184 1.572383 24.155832 0.006606 9.846939 10.910395 1.554528 29.304847 0.0 NaN NaN NaN NaN NaN
146 2020-05-13 Northeastern Massachusetts 158983.000 297113.0 32024.0 514032.0 117.0 20158.0 12.291240 18.018719 56.410076 65.569321 100.0 7.886844 14.739210 1.588650 25.500149 0.005804 19107.0 8.320668 15.549956 1.676035 26.902810 0.006123 21123.0 7.526535 14.065852 1.516073 24.335180 0.005539 20100.666667 7.909340 14.781251 1.593181 25.572883 0.005821 6.842531 17.459562 1.986204 41.008563 0.0 5.491791 14.012982 1.594120 32.913326 0.0
153 2020-05-20 Northeastern Massachusetts 164193.000 320263.0 35174.0 559032.0 117.0 22088.0 12.694034 19.422674 61.958781 71.309468 100.0 7.433584 14.499411 1.592448 25.309308 0.005297 21123.0 7.773186 15.161814 1.665199 26.465559 0.005539 22729.0 7.223943 14.090501 1.547538 24.595539 0.005148 21872.000000 7.506995 14.642602 1.608175 25.559254 0.005349 2.699482 11.994819 1.632124 23.316062 0.0 2.584325 11.483135 1.562500 22.321429 0.0
160 2020-05-27 Northeastern Massachusetts 186775.000 339663.0 40604.0 614332.0 117.0 23370.0 14.439885 20.599207 71.523692 78.363471 100.0 7.992084 14.534146 1.737441 26.287206 0.005006 22729.0 8.217475 14.944036 1.786440 27.028554 0.005148 23852.0 7.830580 14.240441 1.702331 25.755995 0.004905 23264.000000 8.028499 14.600370 1.745358 26.406981 0.005029 17.614665 15.132605 4.235569 43.135725 0.0 14.061021 12.079701 3.381071 34.433375 0.0
161 2020-06-03 Northeastern Massachusetts 193712.000 366013.0 42635.0 688832.0 117.0 24334.0 14.976196 22.197229 75.101286 87.866604 100.0 7.960549 15.041218 1.752075 28.307389 0.004808 23852.0 8.121415 15.345170 1.787481 28.879423 0.004905 24668.5 7.852606 14.837262 1.728317 27.923546 0.004743 24235.666667 7.992848 15.102246 1.759184 28.422243 0.004828 7.196058 27.334025 2.106846 77.282158 0.0 6.177204 23.463936 1.808549 66.340160 0.0
162 2020-06-10 Northeastern Massachusetts 196071.000 375913.0 46315.0 700832.0 117.0 25003.0 15.158575 22.797625 81.583583 89.397310 100.0 7.841899 15.034716 1.852378 28.029916 0.004679 24668.5 7.948234 15.238584 1.877496 28.409997 0.004743 25213.5 7.776429 14.909195 1.836913 27.795903 0.004640 24920.333333 7.867912 15.084590 1.858522 28.122898 0.004695 3.526158 14.798206 5.500747 17.937220 0.0 2.889161 12.124923 4.507042 14.696877 0.0
163 2020-06-17 Northeastern Massachusetts 198897.000 385913.0 49195.0 703632.0 117.0 25424.0 15.377057 23.404085 86.656685 89.754475 100.0 7.823199 15.179083 1.934983 27.675897 0.004602 25213.5 7.888512 15.305808 1.951137 27.906955 0.004640 25579.0 7.775793 15.087103 1.923257 27.508190 0.004574 25387.000000 7.834600 15.201205 1.937803 27.716233 0.004609 6.712589 23.752969 6.840855 6.650831 0.0 5.185321 18.348624 5.284404 5.137615 0.0
164 2020-06-24 Northeastern Massachusetts 200936.000 390163.0 50520.0 726632.0 117.0 25734.0 15.534696 23.661831 88.990664 92.688328 100.0 7.808191 15.161382 1.963162 28.236263 0.004547 25579.0 7.855506 15.253255 1.975058 28.407365 0.004574 25878.0 7.764742 15.077015 1.952237 28.079141 0.004521 25726.666667 7.810417 15.165704 1.963721 28.244312 0.004548 6.577419 13.709677 4.274194 74.193548 0.0 5.578659 11.627907 3.625171 62.927497 0.0
165 2020-07-01 Northeastern Massachusetts 201506.000 391063.0 50870.0 730632.0 117.0 26022.0 15.578764 23.716412 89.607187 93.198563 100.0 7.743678 15.028168 1.954884 28.077473 0.004496 25878.0 7.786769 15.111794 1.965762 28.233712 0.004521 26169.0 7.700180 14.943750 1.943903 27.919752 0.004471 26024.000000 7.743083 15.027014 1.954734 28.075315 0.004496 1.979167 3.125000 1.215278 13.888889 0.0 1.906355 3.010033 1.170569 13.377926 0.0
166 2020-07-08 Northeastern Massachusetts 202526.000 392663.0 51370.0 731132.0 117.0 26316.0 15.657621 23.813446 90.487934 93.262343 100.0 7.695926 14.921075 1.952044 27.782794 0.004446 26169.0 7.739157 15.004891 1.963010 27.938859 0.004471 26487.5 7.646097 14.824464 1.939405 27.602907 0.004417 26332.333333 7.691153 14.911819 1.950834 27.765561 0.004443 3.469388 5.442177 1.700680 1.700680 0.0 3.505155 5.498282 1.718213 1.718213 0.0
167 2020-07-15 Northeastern Massachusetts 207526.000 442163.0 52670.0 739632.0 117.0 26659.0 16.044180 26.815423 92.777876 94.346593 100.0 7.784463 16.585881 1.975693 27.744176 0.004389 26487.5 7.834866 16.693270 1.988485 27.923813 0.004417 26814.0 7.739464 16.490005 1.964272 27.583800 0.004363 26648.000000 7.787676 16.592727 1.976509 27.755629 0.004391 14.577259 144.314869 3.790087 24.781341 0.0 15.698587 155.416013 4.081633 26.687598 0.0
168 2020-07-22 Northeastern Massachusetts 575436.000 857263.0 55670.0 744632.0 117.0 26969.0 44.487913 51.989583 98.062357 94.984387 100.0 21.336942 31.786978 2.064222 27.610664 0.004338 26814.0 21.460282 31.970724 2.076154 27.770269 0.004363 27157.5 21.188843 31.566344 2.049894 27.419019 0.004308 26991.333333 21.319288 31.760676 2.062514 27.587818 0.004335 1186.806452 1339.032258 9.677419 16.129032 0.0 1126.830015 1271.362940 9.188361 15.313936 0.0
169 2020-07-29 Northeastern Massachusetts 876266.000 1225163.0 55820.0 744632.0 117.0 27346.0 67.745580 74.301252 98.326581 94.984387 100.0 32.043663 44.802275 2.041249 27.230015 0.004279 27157.5 32.266078 45.113247 2.055417 27.419019 0.004308 27640.0 31.702822 44.325724 2.019537 26.940376 0.004233 27416.333333 31.961458 44.687340 2.036013 27.160160 0.004268 797.957560 975.862069 0.397878 0.000000 0.0 875.778748 1071.033479 0.436681 0.000000 0.0
170 2020-08-05 Northeastern Massachusetts 891786.000 1242163.0 55920.0 746632.0 117.0 27934.0 68.945457 75.332234 98.502730 95.239504 100.0 31.924751 44.467781 2.001862 26.728431 0.004188 27640.0 32.264327 44.940774 2.023155 27.012735 0.004233 28175.0 31.651677 44.087418 1.984738 26.499805 0.004153 27898.666667 31.965184 44.524099 2.004397 26.762283 0.004194 26.394558 28.911565 0.170068 3.401361 0.0 32.165803 35.233161 0.207254 4.145078 0.0
171 2020-08-12 Northeastern Massachusetts 1119236.000 1473313.0 56270.0 761992.0 117.0 28416.0 86.529994 89.350560 99.119253 97.198808 100.0 39.387528 51.848008 1.980222 26.815597 0.004117 28175.0 39.724437 52.291500 1.997161 27.044969 0.004153 28662.5 39.048792 51.402111 1.963192 26.584980 0.004082 28419.666667 39.382446 51.841319 1.979967 26.812137 0.004117 471.887967 479.564315 0.726141 31.867220 0.0 425.140187 432.056075 0.654206 28.710280 0.0
172 2020-08-19 Northeastern Massachusetts 1289776.000 1643613.0 56470.0 771952.0 117.0 28909.0 99.714725 99.678576 99.471552 98.469294 100.0 44.615033 56.854717 1.953371 26.702826 0.004047 28662.5 44.998727 57.343672 1.970170 26.932473 0.004082 29162.5 44.227210 56.360497 1.936391 26.470707 0.004012 28913.666667 44.607833 56.845540 1.953056 26.698516 0.004047 345.922921 345.436105 0.405680 20.202840 0.0 349.825641 349.333333 0.410256 20.430769 0.0
173 2020-08-26 Northeastern Massachusetts 1292496.000 1643613.0 56720.0 783952.0 117.0 29416.0 99.925012 99.678576 99.911925 100.000000 100.0 43.938537 55.874796 1.928202 26.650530 0.003977 29162.5 44.320480 56.360497 1.944964 26.882195 0.004012 29694.0 43.527177 55.351687 1.910150 26.401024 0.003940 29432.333333 43.914153 55.843789 1.927132 26.635741 0.003975 5.364892 0.000000 0.493097 23.668639 0.0 5.440000 0.000000 0.500000 24.000000 0.0
174 2020-09-02 Northeastern Massachusetts 1292996.000 1648613.0 56770.0 783952.0 117.0 29972.0 99.963668 99.981806 100.000000 100.000000 100.0 43.140131 55.005105 1.894101 26.156146 0.003904 29694.0 43.544016 55.520071 1.911834 26.401024 0.003940 30256.5 42.734487 54.487895 1.876291 25.910201 0.003867 29976.333333 43.133895 54.997153 1.893827 26.152365 0.003903 0.899281 8.992806 0.089928 0.000000 0.0 0.940734 9.407338 0.094073 0.000000 0.0
175 2020-09-09 Northeastern Massachusetts 1293465.941 1648913.0 56770.0 783952.0 117.0 30541.0 100.000000 100.000000 100.000000 100.000000 100.0 42.351787 53.990144 1.858813 25.668839 0.003831 30256.5 42.750019 54.497810 1.876291 25.910201 0.003867 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 0.825907 0.527241 0.000000 0.000000 0.0 0.835451 0.533333 0.000000 0.000000 0.0
In [12]:
# Plot the Ratio of PPE to Confirmed Cases

RATIO1 = []
RATIO2 = []
RATIO3 = []
RATIO4 = []
RATIO5 = []
RATIO6 = []
RATIOS = [RATIO1, RATIO2, RATIO3, RATIO4, RATIO5, RATIO6]
for RATIO in RATIOS:
    for category in categories:
        RATIO.append('{} Ratio {}'.format(category, RATIOS.index(RATIO)+1))
        
fig, ax = plt.subplots(1,1,figsize=(14, 6))
color = ['b', 'g', 'r', 'c', 'm']

for category in categories:
    ax.plot('Time', category, data=NM_CC, color=color[categories.index(category)], linewidth=3, label=category, marker='.', markersize=12)
    ax.set_xlabel('Date', fontsize=15)
    ax.set_ylabel('The number of PPE', fontsize=15)
    ax.set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
    ax.legend(loc='best')
    ax.set_title('The Ratio of PPE Dstribution to Confirmed Cases in Northeastern Massachusetts', fontsize=20)
ax1 = ax.twinx()
for ratio in RATIO1:
    ax1.plot('Time', ratio, data=NM_CC, color=color[RATIO1.index(ratio)], linestyle='--', linewidth=3, label=ratio, marker='^', markersize=8)
    ax1.set_ylabel('Ratio', fontsize=15)
    ax1.legend(loc='best')
plt.show()



fig, axes = plt.subplots(6,1,figsize=(15,48))
color = ['b', 'g', 'r', 'c', 'm']


for RATIO in RATIOS:
    for category in categories:
        axes[RATIOS.index(RATIO)].plot('Time', category, data=NM_CC, color=color[categories.index(category)], linewidth=3, label=category, marker='.', markersize=12)
        axes[RATIOS.index(RATIO)].set_xlabel('Date', fontsize=15)
        axes[RATIOS.index(RATIO)].set_ylabel('The number of PPE', fontsize=15)
        axes[RATIOS.index(RATIO)].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
        axes[RATIOS.index(RATIO)].legend(loc='best')
        axes[RATIOS.index(RATIO)].set_title('The Ratio of PPE Dstribution to Confirmed Cases in Northeastern Massachusetts', fontsize=20)
    ax1 = axes[RATIOS.index(RATIO)].twinx()
    for ratio in RATIO:
        ax1.plot('Time', ratio, data=NM_CC, color=color[RATIO.index(ratio)], linestyle='--', linewidth=3, label=ratio, marker='^', markersize=8)
        ax1.set_ylabel('Ratio', fontsize=15)
        ax1.legend(loc='best')
plt.show()
In [13]:
for category in categories:
    NM_CC['{} delta'.format(category)] = NM_CC[category].diff()
    NM_CC['Confirmed Cases delta'] = NM_CC['Confirmed Cases'].diff()

fig, axes = plt.subplots(2, 3, figsize=(25,15))

for ax, category in zip(axes.flatten(), categories):
    sns.regplot('Confirmed Cases', category, data=NM_CC, ax=ax)
    ax.set_xlabel('Confirmed Cases', fontsize=15)
    ax.set_ylabel(category, fontsize=15)
fig.delaxes(axes[1,2])
fig.suptitle('Regression Plot (Cumulative vs Cumulative)', fontsize=25)

fig1, axes1 = plt.subplots(2, 3, figsize=(25,15))

for ax, category in zip(axes1.flatten(), categories):
    sns.regplot('Confirmed Cases delta', category + ' delta', data=NM_CC, ax=ax)
    ax.set_xlabel('Confirmed Cases', fontsize=15)
    ax.set_ylabel(category, fontsize=15)
fig1.delaxes(axes1[1,2])
fig1.suptitle('Regression Plot (Delta vs Delta)', fontsize=25)
Out[13]:
Text(0.5, 0.98, 'Regression Plot (Delta vs Delta)')
In [14]:
import statsmodels.api as sm
Y = [pd.DataFrame] * 5
X = [pd.DataFrame] * 5
for category in categories:
    Y[categories.index(category)] = NM_CC[category]
    X[categories.index(category)] = NM_CC['Confirmed Cases']
    X[categories.index(category)] = sm.add_constant(X[categories.index(category)])
    model = sm.OLS(Y[categories.index(category)], X[categories.index(category)])
    results = model.fit()
    print(results.summary())
                            OLS Regression Results                            
==============================================================================
Dep. Variable:             N95s/KN95s   R-squared:                       0.542
Model:                            OLS   Adj. R-squared:                  0.517
Method:                 Least Squares   F-statistic:                     21.32
Date:                Sun, 13 Sep 2020   Prob (F-statistic):           0.000214
Time:                        20:58:07   Log-Likelihood:                -281.72
No. Observations:                  20   AIC:                             567.4
Df Residuals:                      18   BIC:                             569.4
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const           -1.692e+06   4.89e+05     -3.459      0.003   -2.72e+06   -6.64e+05
Confirmed Cases    87.9436     19.047      4.617      0.000      47.928     127.959
==============================================================================
Omnibus:                        8.473   Durbin-Watson:                   0.190
Prob(Omnibus):                  0.014   Jarque-Bera (JB):                1.909
Skew:                           0.032   Prob(JB):                        0.385
Kurtosis:                       1.488   Cond. No.                     1.68e+05
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 1.68e+05. This might indicate that there are
strong multicollinearity or other numerical problems.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:                  Masks   R-squared:                       0.579
Model:                            OLS   Adj. R-squared:                  0.556
Method:                 Least Squares   F-statistic:                     24.80
Date:                Sun, 13 Sep 2020   Prob (F-statistic):           9.69e-05
Time:                        20:58:07   Log-Likelihood:                -284.27
No. Observations:                  20   AIC:                             572.5
Df Residuals:                      18   BIC:                             574.5
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const           -1.956e+06   5.56e+05     -3.520      0.002   -3.12e+06   -7.89e+05
Confirmed Cases   107.7427     21.635      4.980      0.000      62.290     153.196
==============================================================================
Omnibus:                        9.258   Durbin-Watson:                   0.193
Prob(Omnibus):                  0.010   Jarque-Bera (JB):                1.974
Skew:                           0.013   Prob(JB):                        0.373
Kurtosis:                       1.461   Cond. No.                     1.68e+05
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 1.68e+05. This might indicate that there are
strong multicollinearity or other numerical problems.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:                  Gowns   R-squared:                       0.951
Model:                            OLS   Adj. R-squared:                  0.949
Method:                 Least Squares   F-statistic:                     352.4
Date:                Sun, 13 Sep 2020   Prob (F-statistic):           2.87e-13
Time:                        20:58:07   Log-Likelihood:                -183.01
No. Observations:                  20   AIC:                             370.0
Df Residuals:                      18   BIC:                             372.0
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const           -1.758e+04   3515.045     -5.000      0.000    -2.5e+04   -1.02e+04
Confirmed Cases     2.5693      0.137     18.771      0.000       2.282       2.857
==============================================================================
Omnibus:                        1.546   Durbin-Watson:                   0.404
Prob(Omnibus):                  0.462   Jarque-Bera (JB):                1.014
Skew:                          -0.225   Prob(JB):                        0.602
Kurtosis:                       1.993   Cond. No.                     1.68e+05
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 1.68e+05. This might indicate that there are
strong multicollinearity or other numerical problems.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:                 Gloves   R-squared:                       0.955
Model:                            OLS   Adj. R-squared:                  0.952
Method:                 Least Squares   F-statistic:                     379.5
Date:                Sun, 13 Sep 2020   Prob (F-statistic):           1.52e-13
Time:                        20:58:07   Log-Likelihood:                -231.77
No. Observations:                  20   AIC:                             467.5
Df Residuals:                      18   BIC:                             469.5
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const           -9.519e+04   4.02e+04     -2.365      0.029    -1.8e+05   -1.06e+04
Confirmed Cases    30.5327      1.567     19.481      0.000      27.240      33.825
==============================================================================
Omnibus:                        1.301   Durbin-Watson:                   0.329
Prob(Omnibus):                  0.522   Jarque-Bera (JB):                0.869
Skew:                          -0.109   Prob(JB):                        0.648
Kurtosis:                       2.002   Cond. No.                     1.68e+05
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 1.68e+05. This might indicate that there are
strong multicollinearity or other numerical problems.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:            Ventilators   R-squared:                        -inf
Model:                            OLS   Adj. R-squared:                   -inf
Method:                 Least Squares   F-statistic:                    -18.00
Date:                Sun, 13 Sep 2020   Prob (F-statistic):               1.00
Time:                        20:58:07   Log-Likelihood:                 587.29
No. Observations:                  20   AIC:                            -1171.
Df Residuals:                      18   BIC:                            -1169.
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const             117.0000   6.59e-14   1.77e+15      0.000     117.000     117.000
Confirmed Cases  1.735e-18   2.57e-18      0.676      0.508   -3.66e-18    7.13e-18
==============================================================================
Omnibus:                        0.186   Durbin-Watson:                   0.011
Prob(Omnibus):                  0.911   Jarque-Bera (JB):                0.017
Skew:                           0.011   Prob(JB):                        0.992
Kurtosis:                       2.859   Cond. No.                     1.68e+05
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 1.68e+05. This might indicate that there are
strong multicollinearity or other numerical problems.







Metro West

Metro West is the region with the most deaths number.

In [15]:
MW = df.loc[df['Region']=='Metro West']
MW_CC = MW.dropna()
categories = ['N95s/KN95s', 'Masks', 'Gowns', 'Gloves', 'Ventilators']
for category in categories:
    MW_CC['{} %'.format(category)] = MW_CC[category]/MW_CC[category].iloc[-1] * 100
    
fig, axes = plt.subplots(2, 3, figsize=(25,15))
for ax, category in zip(axes.flatten(), categories):
    sns.distplot(MW_CC[category].diff(), ax=ax)
    ax.set_xlabel(category, fontsize=15)
fig.delaxes(axes[1,2])
MW_CC
Out[15]:
Time Region N95s/KN95s Masks Gowns Gloves Ventilators Confirmed Cases N95s/KN95s % Masks % Gowns % Gloves % Ventilators %
88 2020-04-29 Metro West 212466.000 373412.0 50610.0 372180.0 136.0 12601.0 12.069462 17.771521 27.322640 25.838548 100.0
95 2020-05-06 Metro West 292073.000 475762.0 55812.0 592330.0 136.0 14825.0 16.591661 22.642589 30.131026 41.122434 100.0
102 2020-05-13 Metro West 336159.000 564732.0 71127.0 701630.0 136.0 16491.0 19.096035 26.876872 38.399080 48.710572 100.0
109 2020-05-20 Metro West 380619.000 610582.0 88237.0 870902.0 136.0 17755.0 21.621655 29.058977 47.636195 60.462259 100.0
116 2020-05-27 Metro West 449855.000 661482.0 128047.0 977602.0 136.0 18580.0 25.554713 31.481423 69.128278 67.869892 100.0
117 2020-06-03 Metro West 463396.000 687532.0 135759.0 1052774.0 136.0 19245.0 26.323931 32.721202 73.291728 73.088699 100.0
118 2020-06-10 Metro West 479836.000 722682.0 145989.0 1121074.0 136.0 19490.0 27.257831 34.394070 78.814561 77.830417 100.0
119 2020-06-17 Metro West 486648.000 724682.0 148709.0 1182274.0 136.0 19706.0 27.644797 34.489254 80.282998 82.079219 100.0
120 2020-06-24 Metro West 514245.000 730682.0 150139.0 1188574.0 136.0 19906.0 29.212488 34.774808 81.055007 82.516596 100.0
121 2020-07-01 Metro West 516985.000 737682.0 154039.0 1233574.0 136.0 20047.0 29.368137 35.107954 83.160486 85.640715 100.0
122 2020-07-08 Metro West 518680.000 737682.0 160914.0 1246574.0 136.0 20195.0 29.464425 35.107954 86.872068 86.543239 100.0
123 2020-07-15 Metro West 535320.000 783032.0 162441.0 1319174.0 136.0 20346.0 30.409686 37.266263 87.696444 91.583484 100.0
124 2020-07-22 Metro West 978560.000 1232432.0 163441.0 1319574.0 136.0 20589.0 55.588624 58.654224 88.236310 91.611254 100.0
125 2020-07-29 Metro West 1221330.000 1510082.0 169731.0 1358574.0 136.0 20880.0 69.379551 71.868215 91.632070 94.318824 100.0
126 2020-08-05 Metro West 1229780.000 1538182.0 172781.0 1368374.0 136.0 21274.0 69.859567 73.205558 93.278663 94.999188 100.0
127 2020-08-12 Metro West 1555340.000 1880582.0 173181.0 1379534.0 136.0 21530.0 88.353509 89.501147 93.494609 95.773969 100.0
128 2020-08-19 Metro West 1751980.000 2076382.0 177881.0 1397406.0 136.0 21831.0 99.523950 98.819712 96.031982 97.014731 100.0
129 2020-08-26 Metro West 1759100.000 2100882.0 180031.0 1431206.0 136.0 22179.0 99.928413 99.985722 97.192695 99.361291 100.0
130 2020-09-02 Metro West 1759850.000 2100982.0 184681.0 1439806.0 136.0 22598.0 99.971018 99.990482 99.703073 99.958345 100.0
131 2020-09-09 Metro West 1760360.188 2101182.0 185231.0 1440406.0 136.0 22949.0 100.000000 100.000000 100.000000 100.000000 100.0
In [16]:
# Confirmed cases vs PPE distribution
fig, axes = plt.subplots(2,1,figsize=(15,14))

percentages = ['N95s/KN95s %', 'Masks %', 'Gowns %', 'Gloves %', 'Ventilators %']

for category in categories:
    axes[0].plot('Time', category, data=MW_CC, marker='.', markersize=10)

axes[0].set_xlabel('Date', fontsize=15)
axes[0].set_ylabel('The Number of PPE Distribution', fontsize=15)
axes[0].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
axes[0].tick_params(direction='out', length=6, width=2, labelsize=10)
axes[0].legend()
axes[0].set_title('PPE Distribution vs Confirmed Cases in MW', fontsize=20)

ax1 = axes[0].twinx()
ax1.plot('Time', 'Confirmed Cases', data=MW_CC, color='y', linestyle='--', linewidth=3, label='Confirmed Cases')

ax1.set_ylabel('Confirmed Cases', fontsize=15)
ax1.tick_params(direction='out', length=6, width=2, labelsize=10)
ax1.legend(loc='upper right')


for percentage in percentages:
    axes[1].plot('Time', percentage, data=MW_CC, marker='.', markersize=10)

axes[1].set_xlabel('Date', fontsize=15)
axes[1].set_ylabel('PPE Distribution %', fontsize=15)
axes[1].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
axes[1].tick_params(direction='out', length=6, width=2, labelsize=10)
axes[1].legend()
axes[1].set_title('PPE Distribution Percentage vs Confirmed Cases in MW', fontsize=20)

ax2 = axes[1].twinx()
ax2.plot('Time', 'Confirmed Cases', data=MW_CC, color='y', linestyle='--', linewidth=3, label='Confirmed Cases')

ax2.set_ylabel('Confirmed Cases', fontsize=15)
ax2.tick_params(direction='out', length=6, width=2, labelsize=10)
ax2.legend(loc='upper right')

plt.show()
In [17]:
pd.set_option("display.max_rows", None, "display.max_columns", None)


# Calculate the ratio of cumulative PPE data to cumulative confirmed cases data (Ratio 1)
for category in categories:
    MW_CC['{} Ratio 1'.format(category)] = MW_CC[category]/MW_CC['Confirmed Cases']
    
    
    
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 2)
# (Interval=2 weeks, one week before + the week itself)
MW_CC['Confirmed Cases(ma1)'] = MW_CC['Confirmed Cases'].rolling(window=2,center=False).mean()
MW_CC.iloc[0,-1] = (9219+12601) / 2
for category in categories:
    MW_CC['{} Ratio 2'.format(category)] = MW_CC[category]/MW_CC['Confirmed Cases(ma1)']





# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 3)
# (Interval=2 weeks, one week after + the week itself)
MW_CC['Confirmed Cases(ma2)'] = MW_CC['Confirmed Cases'].rolling(window=2,center=False).mean().shift(-1)
for category in categories:
    MW_CC['{} Ratio 3'.format(category)] = MW_CC[category]/MW_CC['Confirmed Cases(ma2)']

    
    
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 4)
# (Interval=3 weeks, one week before + one week after + the week itself)
MW_CC['Confirmed Cases(ma3)'] = MW_CC['Confirmed Cases'].rolling(window=3,center=False).mean().shift(-1)
MW_CC.iloc[0,-1] = (9219+12601+14825)/3
for category in categories:
    MW_CC['{} Ratio 4'.format(category)] = MW_CC[category]/MW_CC['Confirmed Cases(ma3)']

    
    
# Calculate the ratio of delta PPE data to delta confirmed cases data (Ratio 5)
for category in categories:
    MW_CC['{} Ratio 5'.format(category)] = MW_CC[category].diff()/MW_CC['Confirmed Cases'].diff()
    
    
    
# Calculate the ratio of delta PPE data to moving average delta confirmed cases data (Ratio 6)
for category in categories:
    MW_CC['{} Ratio 6'.format(category)] = MW_CC[category].diff()/MW_CC['Confirmed Cases'].diff().rolling(window=2,center=False).mean()
MW_CC
Out[17]:
Time Region N95s/KN95s Masks Gowns Gloves Ventilators Confirmed Cases N95s/KN95s % Masks % Gowns % Gloves % Ventilators % N95s/KN95s Ratio 1 Masks Ratio 1 Gowns Ratio 1 Gloves Ratio 1 Ventilators Ratio 1 Confirmed Cases(ma1) N95s/KN95s Ratio 2 Masks Ratio 2 Gowns Ratio 2 Gloves Ratio 2 Ventilators Ratio 2 Confirmed Cases(ma2) N95s/KN95s Ratio 3 Masks Ratio 3 Gowns Ratio 3 Gloves Ratio 3 Ventilators Ratio 3 Confirmed Cases(ma3) N95s/KN95s Ratio 4 Masks Ratio 4 Gowns Ratio 4 Gloves Ratio 4 Ventilators Ratio 4 N95s/KN95s Ratio 5 Masks Ratio 5 Gowns Ratio 5 Gloves Ratio 5 Ventilators Ratio 5 N95s/KN95s Ratio 6 Masks Ratio 6 Gowns Ratio 6 Gloves Ratio 6 Ventilators Ratio 6
88 2020-04-29 Metro West 212466.000 373412.0 50610.0 372180.0 136.0 12601.0 12.069462 17.771521 27.322640 25.838548 100.0 16.861043 29.633521 4.016348 29.535751 0.010793 10910.0 19.474427 34.226581 4.638863 34.113657 0.012466 13713.0 15.493765 27.230511 3.690658 27.140669 0.009918 12215.000000 17.393860 30.569955 4.143266 30.469095 0.011134 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
95 2020-05-06 Metro West 292073.000 475762.0 55812.0 592330.0 136.0 14825.0 16.591661 22.642589 30.131026 41.122434 100.0 19.701383 32.091872 3.764722 39.954806 0.009174 13713.0 21.298986 34.694232 4.070007 43.194779 0.009918 15658.0 18.653276 30.384596 3.564440 37.829225 0.008686 14639.000000 19.951704 32.499624 3.812556 40.462463 0.009290 35.794514 46.020683 2.339029 98.988309 0.0 NaN NaN NaN NaN NaN
102 2020-05-13 Metro West 336159.000 564732.0 71127.0 701630.0 136.0 16491.0 19.096035 26.876872 38.399080 48.710572 100.0 20.384391 34.244861 4.313080 42.546237 0.008247 15658.0 21.468834 36.066675 4.542534 44.809682 0.008686 17123.0 19.632015 32.980903 4.153887 40.975880 0.007943 16357.000000 20.551385 34.525402 4.348414 42.894785 0.008314 26.462185 53.403361 9.192677 65.606242 0.0 22.666324 45.742931 7.874036 56.195373 0.0
109 2020-05-20 Metro West 380619.000 610582.0 88237.0 870902.0 136.0 17755.0 21.621655 29.058977 47.636195 60.462259 100.0 21.437285 34.389299 4.969699 49.051084 0.007660 17123.0 22.228523 35.658588 5.153127 50.861531 0.007943 18167.5 20.950544 33.608477 4.856860 47.937361 0.007486 17608.666667 21.615436 34.675084 5.010998 49.458714 0.007723 35.174051 36.273734 13.536392 133.917722 0.0 30.348123 31.296928 11.679181 115.544027 0.0
116 2020-05-27 Metro West 449855.000 661482.0 128047.0 977602.0 136.0 18580.0 25.554713 31.481423 69.128278 67.869892 100.0 24.211787 35.601830 6.891658 52.615823 0.007320 18167.5 24.761525 36.410183 7.048135 53.810486 0.007486 18912.5 23.786120 34.975915 6.770496 51.690787 0.007191 18526.666667 24.281486 35.704318 6.911497 52.767290 0.007341 83.922424 61.696970 48.254545 129.333333 0.0 66.286261 48.731450 38.113930 102.154141 0.0
117 2020-06-03 Metro West 463396.000 687532.0 135759.0 1052774.0 136.0 19245.0 26.323931 32.721202 73.291728 73.088699 100.0 24.078774 35.725227 7.054248 54.703767 0.007067 18912.5 24.502102 36.353311 7.178268 55.665512 0.007191 19367.5 23.926475 35.499264 7.009630 54.357764 0.007022 19105.000000 24.255221 35.987019 7.105941 55.104632 0.007119 20.362406 39.172932 11.596992 113.040602 0.0 18.175839 34.966443 10.351678 100.902013 0.0
118 2020-06-10 Metro West 479836.000 722682.0 145989.0 1121074.0 136.0 19490.0 27.257831 34.394070 78.814561 77.830417 100.0 24.619600 37.079631 7.490457 57.520472 0.006978 19367.5 24.775319 37.314160 7.537834 57.884291 0.007022 19598.0 24.483927 36.875293 7.449178 57.203490 0.006939 19480.333333 24.631817 37.098030 7.494174 57.549015 0.006981 67.102041 143.469388 41.755102 278.775510 0.0 36.131868 77.252747 22.483516 150.109890 0.0
119 2020-06-17 Metro West 486648.000 724682.0 148709.0 1182274.0 136.0 19706.0 27.644797 34.489254 80.282998 82.079219 100.0 24.695423 36.774688 7.546382 59.995636 0.006901 19598.0 24.831513 36.977345 7.587968 60.326258 0.006939 19806.0 24.570736 36.589013 7.508280 59.692719 0.006867 19700.666667 24.702108 36.784643 7.548425 60.011878 0.006903 31.537037 9.259259 12.592593 283.333333 0.0 29.553145 8.676790 11.800434 265.509761 0.0
120 2020-06-24 Metro West 514245.000 730682.0 150139.0 1188574.0 136.0 19906.0 29.212488 34.774808 81.055007 82.516596 100.0 25.833668 36.706621 7.542399 59.709334 0.006832 19806.0 25.964102 36.891952 7.580481 60.010805 0.006867 19976.5 25.742497 36.577078 7.515781 59.498611 0.006808 19886.333333 25.859217 36.742922 7.549858 59.768384 0.006839 137.985000 30.000000 7.150000 31.500000 0.0 132.677885 28.846154 6.875000 30.288462 0.0
121 2020-07-01 Metro West 516985.000 737682.0 154039.0 1233574.0 136.0 20047.0 29.368137 35.107954 83.160486 85.640715 100.0 25.788647 36.797626 7.683893 61.534095 0.006784 19976.5 25.879659 36.927490 7.711010 61.751258 0.006808 20121.0 25.693802 36.662293 7.655633 61.307788 0.006759 20049.333333 25.785645 36.793343 7.682999 61.526934 0.006783 19.432624 49.645390 27.659574 319.148936 0.0 16.070381 41.055718 22.873900 263.929619 0.0
122 2020-07-08 Metro West 518680.000 737682.0 160914.0 1246574.0 136.0 20195.0 29.464425 35.107954 86.872068 86.543239 100.0 25.683585 36.527952 7.968012 61.726863 0.006734 20121.0 25.778043 36.662293 7.997316 61.953879 0.006759 20270.5 25.587923 36.391900 7.938334 61.496954 0.006709 20196.000000 25.682313 36.526144 7.967617 61.723807 0.006734 11.452703 0.000000 46.452703 87.837838 0.0 11.730104 0.000000 47.577855 89.965398 0.0
123 2020-07-15 Metro West 535320.000 783032.0 162441.0 1319174.0 136.0 20346.0 30.409686 37.266263 87.696444 91.583484 100.0 26.310823 38.485796 7.983928 64.837020 0.006684 20270.5 26.408821 38.629141 8.013665 65.078513 0.006709 20467.5 26.154635 38.257335 7.936534 64.452131 0.006645 20376.666667 26.271225 38.427875 7.971912 64.739441 0.006674 110.198675 300.331126 10.112583 480.794702 0.0 111.304348 303.344482 10.214047 485.618729 0.0
124 2020-07-22 Metro West 978560.000 1232432.0 163441.0 1319574.0 136.0 20589.0 55.588624 58.654224 88.236310 91.611254 100.0 47.528292 59.858760 7.938268 64.091214 0.006605 20467.5 47.810431 60.214096 7.985391 64.471675 0.006645 20734.5 47.194772 59.438713 7.882563 63.641467 0.006559 20605.000000 47.491386 59.812279 7.932104 64.041446 0.006600 1824.032922 1849.382716 4.115226 1.646091 0.0 2249.949239 2281.218274 5.076142 2.030457 0.0
125 2020-07-29 Metro West 1221330.000 1510082.0 169731.0 1358574.0 136.0 20880.0 69.379551 71.868215 91.632070 94.318824 100.0 58.492816 72.321935 8.128879 65.065805 0.006513 20734.5 58.903277 72.829439 8.185922 65.522390 0.006559 21077.0 57.946102 71.645965 8.052901 64.457655 0.006453 20914.333333 58.396793 72.203210 8.115535 64.958991 0.006503 834.261168 954.123711 21.615120 134.020619 0.0 909.250936 1039.887640 23.558052 146.067416 0.0
126 2020-08-05 Metro West 1229780.000 1538182.0 172781.0 1368374.0 136.0 21274.0 69.859567 73.205558 93.278663 94.999188 100.0 57.806712 72.303375 8.121698 64.321425 0.006393 21077.0 58.347013 72.979172 8.197609 64.922617 0.006453 21402.0 57.460985 71.870947 8.073124 63.936735 0.006355 21228.000000 57.931977 72.460053 8.139297 64.460806 0.006407 21.446701 71.319797 7.741117 24.873096 0.0 24.671533 82.043796 8.905109 28.613139 0.0
127 2020-08-12 Metro West 1555340.000 1880582.0 173181.0 1379534.0 136.0 21530.0 88.353509 89.501147 93.494609 95.773969 100.0 72.240595 87.347051 8.043706 64.074965 0.006317 21402.0 72.672647 87.869451 8.091814 64.458181 0.006355 21680.5 71.739120 86.740712 7.987869 63.630175 0.006273 21545.000000 72.190299 87.286238 8.038106 64.030355 0.006312 1271.718750 1337.500000 1.562500 43.593750 0.0 1001.723077 1053.538462 1.230769 34.338462 0.0
128 2020-08-19 Metro West 1751980.000 2076382.0 177881.0 1397406.0 136.0 21831.0 99.523950 98.819712 96.031982 97.014731 100.0 80.251935 95.111630 8.148092 64.010169 0.006230 21680.5 80.809022 95.771869 8.204654 64.454510 0.006273 22005.0 79.617360 94.359555 8.083663 63.504022 0.006180 21846.666667 80.194385 95.043424 8.142249 63.964266 0.006225 653.289037 650.498339 15.614618 59.375415 0.0 706.068223 703.052065 16.876122 64.172352 0.0
129 2020-08-26 Metro West 1759100.000 2100882.0 180031.0 1431206.0 136.0 22179.0 99.928413 99.985722 97.192695 99.361291 100.0 79.313765 94.723928 8.117183 64.529780 0.006132 22005.0 79.940923 95.472938 8.181368 65.040036 0.006180 22388.5 78.571588 93.837551 8.041227 63.925944 0.006075 22202.666667 79.229222 94.622958 8.108531 64.460996 0.006125 20.459770 70.402299 6.178161 97.126437 0.0 21.941448 75.500770 6.625578 104.160247 0.0
130 2020-09-02 Metro West 1759850.000 2100982.0 184681.0 1439806.0 136.0 22598.0 99.971018 99.990482 99.703073 99.958345 100.0 77.876361 92.972033 8.172449 63.713868 0.006018 22388.5 78.605087 93.842017 8.248922 64.310070 0.006075 22773.5 77.276220 92.255560 8.109469 63.222869 0.005972 22575.333333 77.954552 93.065381 8.180654 63.777840 0.006024 1.789976 0.238663 11.097852 20.525060 0.0 1.955671 0.260756 12.125163 22.425033 0.0
131 2020-09-09 Metro West 1760360.188 2101182.0 185231.0 1440406.0 136.0 22949.0 100.000000 100.000000 100.000000 100.000000 100.0 76.707490 91.558761 8.071419 62.765524 0.005926 22773.5 77.298623 92.264342 8.133620 63.249215 0.005972 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 1.453527 0.569801 1.566952 1.709402 0.0 1.325164 0.519481 1.428571 1.558442 0.0
In [18]:
# Plot the Ratio of PPE to Confirmed Cases

RATIO1 = []
RATIO2 = []
RATIO3 = []
RATIO4 = []
RATIO5 = []
RATIO6 = []
RATIOS = [RATIO1, RATIO2, RATIO3, RATIO4, RATIO5, RATIO6]
for RATIO in RATIOS:
    for category in categories:
        RATIO.append('{} Ratio {}'.format(category, RATIOS.index(RATIO)+1))
        
        
fig, ax = plt.subplots(1,1,figsize=(14, 6))
color = ['b', 'g', 'r', 'c', 'm']

for category in categories:
    ax.plot('Time', category, data=MW_CC, color=color[categories.index(category)], linewidth=3, label=category, marker='.', markersize=12)
    ax.set_xlabel('Date', fontsize=15)
    ax.set_ylabel('The number of PPE', fontsize=15)
    ax.set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
    ax.legend(loc='best')
    ax.set_title('The Ratio of PPE Dstribution to Confirmed Cases in Southeastern Massachusetts', fontsize=20)
ax1 = ax.twinx()
for ratio in RATIO1:
    ax1.plot('Time', ratio, data=MW_CC, color=color[RATIO1.index(ratio)], linestyle='--', linewidth=3, label=ratio, marker='^', markersize=8)
    ax1.set_ylabel('Ratio', fontsize=15)
    ax1.legend(loc='best')
plt.show()


fig, axes = plt.subplots(6,1,figsize=(15,48))
color = ['b', 'g', 'r', 'c', 'm']


for RATIO in RATIOS:
    for category in categories:
        axes[RATIOS.index(RATIO)].plot('Time', category, data=MW_CC, color=color[categories.index(category)], linewidth=3, label=category, marker='.', markersize=12)
        axes[RATIOS.index(RATIO)].set_xlabel('Date', fontsize=15)
        axes[RATIOS.index(RATIO)].set_ylabel('The number of PPE', fontsize=15)
        axes[RATIOS.index(RATIO)].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
        axes[RATIOS.index(RATIO)].legend(loc='best')
        axes[RATIOS.index(RATIO)].set_title('The Ratio of PPE Dstribution to Confirmed Cases in Metro West', fontsize=20)
    ax1 = axes[RATIOS.index(RATIO)].twinx()
    for ratio in RATIO:
        ax1.plot('Time', ratio, data=MW_CC, color=color[RATIO.index(ratio)], linestyle='--', linewidth=3, label=ratio, marker='^', markersize=8)
        ax1.set_ylabel('Ratio', fontsize=15)
        ax1.legend(loc='best')
plt.show()
In [19]:
for category in categories:
    MW_CC['{} delta'.format(category)] = MW_CC[category].diff()
    MW_CC['Confirmed Cases delta'] = MW_CC['Confirmed Cases'].diff()

fig, axes = plt.subplots(2, 3, figsize=(25,15))

for ax, category in zip(axes.flatten(), categories):
    sns.regplot('Confirmed Cases', category, data=MW_CC, ax=ax)
    ax.set_xlabel('Confirmed Cases', fontsize=15)
    ax.set_ylabel(category, fontsize=15)
fig.delaxes(axes[1,2])
fig.suptitle('Regression Plot (Cumulative vs Cumulative)', fontsize=25)

fig1, axes1 = plt.subplots(2, 3, figsize=(25,15))

for ax, category in zip(axes1.flatten(), categories):
    sns.regplot('Confirmed Cases delta', category + ' delta', data=MW_CC, ax=ax)
    ax.set_xlabel('Confirmed Cases', fontsize=15)
    ax.set_ylabel(category, fontsize=15)
fig1.delaxes(axes1[1,2])
fig1.suptitle('Regression Plot (Delta vs Delta)', fontsize=25)
Out[19]:
Text(0.5, 0.98, 'Regression Plot (Delta vs Delta)')
In [20]:
import statsmodels.api as sm
Y = [pd.DataFrame] * 5
X = [pd.DataFrame] * 5
for category in categories:
    Y[categories.index(category)] = MW_CC[category]
    X[categories.index(category)] = MW_CC['Confirmed Cases']
    X[categories.index(category)] = sm.add_constant(X[categories.index(category)])
    model = sm.OLS(Y[categories.index(category)], X[categories.index(category)])
    results = model.fit()
    print(results.summary())
                            OLS Regression Results                            
==============================================================================
Dep. Variable:             N95s/KN95s   R-squared:                       0.609
Model:                            OLS   Adj. R-squared:                  0.587
Method:                 Least Squares   F-statistic:                     28.00
Date:                Sun, 13 Sep 2020   Prob (F-statistic):           4.97e-05
Time:                        20:58:14   Log-Likelihood:                -283.76
No. Observations:                  20   AIC:                             571.5
Df Residuals:                      18   BIC:                             573.5
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const            -2.54e+06   6.48e+05     -3.920      0.001    -3.9e+06   -1.18e+06
Confirmed Cases   173.0176     32.699      5.291      0.000     104.318     241.717
==============================================================================
Omnibus:                        7.908   Durbin-Watson:                   0.209
Prob(Omnibus):                  0.019   Jarque-Bera (JB):                1.930
Skew:                           0.163   Prob(JB):                        0.381
Kurtosis:                       1.513   Cond. No.                     1.55e+05
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 1.55e+05. This might indicate that there are
strong multicollinearity or other numerical problems.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:                  Masks   R-squared:                       0.622
Model:                            OLS   Adj. R-squared:                  0.601
Method:                 Least Squares   F-statistic:                     29.58
Date:                Sun, 13 Sep 2020   Prob (F-statistic):           3.63e-05
Time:                        20:58:14   Log-Likelihood:                -285.20
No. Observations:                  20   AIC:                             574.4
Df Residuals:                      18   BIC:                             576.4
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const           -2.638e+06   6.96e+05     -3.789      0.001    -4.1e+06   -1.17e+06
Confirmed Cases   191.0928     35.138      5.438      0.000     117.271     264.914
==============================================================================
Omnibus:                        8.311   Durbin-Watson:                   0.194
Prob(Omnibus):                  0.016   Jarque-Bera (JB):                1.945
Skew:                           0.136   Prob(JB):                        0.378
Kurtosis:                       1.497   Cond. No.                     1.55e+05
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 1.55e+05. This might indicate that there are
strong multicollinearity or other numerical problems.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:                  Gowns   R-squared:                       0.940
Model:                            OLS   Adj. R-squared:                  0.937
Method:                 Least Squares   F-statistic:                     284.0
Date:                Sun, 13 Sep 2020   Prob (F-statistic):           1.81e-12
Time:                        20:58:14   Log-Likelihood:                -212.87
No. Observations:                  20   AIC:                             429.7
Df Residuals:                      18   BIC:                             431.7
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const           -1.698e+05   1.87e+04     -9.077      0.000   -2.09e+05   -1.31e+05
Confirmed Cases    15.9169      0.944     16.854      0.000      13.933      17.901
==============================================================================
Omnibus:                        4.513   Durbin-Watson:                   0.928
Prob(Omnibus):                  0.105   Jarque-Bera (JB):                2.497
Skew:                          -0.801   Prob(JB):                        0.287
Kurtosis:                       3.657   Cond. No.                     1.55e+05
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 1.55e+05. This might indicate that there are
strong multicollinearity or other numerical problems.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:                 Gloves   R-squared:                       0.973
Model:                            OLS   Adj. R-squared:                  0.971
Method:                 Least Squares   F-statistic:                     639.0
Date:                Sun, 13 Sep 2020   Prob (F-statistic):           1.63e-15
Time:                        20:58:14   Log-Likelihood:                -244.43
No. Observations:                  20   AIC:                             492.9
Df Residuals:                      18   BIC:                             494.9
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const           -1.124e+06   9.07e+04    -12.392      0.000   -1.31e+06   -9.33e+05
Confirmed Cases   115.6837      4.576     25.279      0.000     106.069     125.298
==============================================================================
Omnibus:                        0.827   Durbin-Watson:                   0.455
Prob(Omnibus):                  0.661   Jarque-Bera (JB):                0.749
Skew:                          -0.192   Prob(JB):                        0.688
Kurtosis:                       2.134   Cond. No.                     1.55e+05
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 1.55e+05. This might indicate that there are
strong multicollinearity or other numerical problems.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:            Ventilators   R-squared:                        -inf
Model:                            OLS   Adj. R-squared:                   -inf
Method:                 Least Squares   F-statistic:                    -18.00
Date:                Sun, 13 Sep 2020   Prob (F-statistic):               1.00
Time:                        20:58:14   Log-Likelihood:                 573.48
No. Observations:                  20   AIC:                            -1143.
Df Residuals:                      18   BIC:                            -1141.
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const             136.0000   1.57e-13   8.65e+14      0.000     136.000     136.000
Confirmed Cases -1.735e-18   7.94e-18     -0.219      0.829   -1.84e-17    1.49e-17
==============================================================================
Omnibus:                      466.626   Durbin-Watson:                   0.000
Prob(Omnibus):                  0.000   Jarque-Bera (JB):                7.500
Skew:                           0.000   Prob(JB):                       0.0235
Kurtosis:                       0.000   Cond. No.                     1.55e+05
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 1.55e+05. This might indicate that there are
strong multicollinearity or other numerical problems.







Metro Boston

In [21]:
MB = df.loc[df['Region']=='Metro Boston']
MB_CC = MB.dropna()
categories = ['N95s/KN95s', 'Masks', 'Gowns', 'Gloves', 'Ventilators']
for category in categories:
    MB_CC['{} %'.format(category)] = MB_CC[category]/MB_CC[category].iloc[-1] * 100
    
fig, axes = plt.subplots(2, 3, figsize=(25,15))
for ax, category in zip(axes.flatten(), categories):
    sns.distplot(MB_CC[category].diff(), ax=ax)
    ax.set_xlabel(category, fontsize=15)
fig.delaxes(axes[1,2])
MB_CC
Out[21]:
Time Region N95s/KN95s Masks Gowns Gloves Ventilators Confirmed Cases N95s/KN95s % Masks % Gowns % Gloves % Ventilators %
44 2020-04-29 Metro Boston 94235.0 130800.0 23036.0 465692.0 204.0 12539.0 24.432138 26.723874 42.571751 58.967612 100.0
51 2020-05-06 Metro Boston 115642.0 146600.0 27956.0 535892.0 204.0 14476.0 29.982292 29.951987 51.664172 67.856591 100.0
58 2020-05-13 Metro Boston 127621.0 187600.0 31366.0 575792.0 204.0 15587.0 33.088066 38.328736 57.966033 72.908874 100.0
65 2020-05-20 Metro Boston 135101.0 217400.0 37846.0 626992.0 204.0 16962.0 35.027392 44.417203 69.941417 79.392004 100.0
72 2020-05-27 Metro Boston 157158.0 234150.0 43206.0 646892.0 204.0 17596.0 40.746070 47.839412 79.846981 81.911814 100.0
73 2020-06-03 Metro Boston 159715.0 238150.0 46156.0 676892.0 204.0 18108.0 41.409019 48.656655 85.298738 85.710523 100.0
74 2020-06-10 Metro Boston 161838.0 242350.0 47216.0 673292.0 204.0 18398.0 41.959445 49.514761 87.257674 85.254678 100.0
75 2020-06-17 Metro Boston 163040.0 246350.0 48436.0 678892.0 204.0 18652.0 42.271086 50.332005 89.512299 85.963770 100.0
76 2020-06-24 Metro Boston 163736.0 251350.0 48511.0 691942.0 204.0 18805.0 42.451536 51.353560 89.650903 87.616209 100.0
77 2020-07-01 Metro Boston 165116.0 256850.0 49011.0 701342.0 204.0 18978.0 42.809326 52.477270 90.574929 88.806471 100.0
78 2020-07-08 Metro Boston 168236.0 259850.0 49511.0 716342.0 204.0 19186.0 43.618243 53.090203 91.498956 90.705825 100.0
79 2020-07-15 Metro Boston 179881.0 294100.0 51711.0 720342.0 204.0 19428.0 46.637421 60.087854 95.564673 91.212320 100.0
80 2020-07-22 Metro Boston 345331.0 467100.0 54111.0 720342.0 204.0 19637.0 89.533343 95.433650 100.000000 91.212320 100.0
81 2020-07-29 Metro Boston 370891.0 475350.0 54111.0 720342.0 204.0 19940.0 96.160238 97.119215 100.000000 91.212320 100.0
82 2020-08-05 Metro Boston 371961.0 478450.0 54111.0 722342.0 204.0 20448.0 96.437655 97.752579 100.000000 91.465567 100.0
83 2020-08-12 Metro Boston 371961.0 478450.0 54111.0 785742.0 204.0 20899.0 96.437655 97.752579 100.000000 99.493505 100.0
84 2020-08-19 Metro Boston 372901.0 478450.0 54111.0 785742.0 204.0 21393.0 96.681367 97.752579 100.000000 99.493505 100.0
85 2020-08-26 Metro Boston 384201.0 478450.0 54111.0 789742.0 204.0 21946.0 99.611098 97.752579 100.000000 100.000000 100.0
86 2020-09-02 Metro Boston 384701.0 489450.0 54111.0 789742.0 204.0 22508.0 99.740732 100.000000 100.000000 100.000000 100.0
87 2020-09-09 Metro Boston 385701.0 489450.0 54111.0 789742.0 204.0 22831.0 100.000000 100.000000 100.000000 100.000000 100.0
In [22]:
# Confirmed cases vs PPE distribution
fig, axes = plt.subplots(2,1,figsize=(15,14))

percentages = ['N95s/KN95s %', 'Masks %', 'Gowns %', 'Gloves %', 'Ventilators %']

for category in categories:
    axes[0].plot('Time', category, data=MB_CC, marker='.', markersize=10)

axes[0].set_xlabel('Date', fontsize=15)
axes[0].set_ylabel('The Number of PPE Distribution', fontsize=15)
axes[0].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
axes[0].tick_params(direction='out', length=6, width=2, labelsize=10)
axes[0].legend()
axes[0].set_title('PPE Distribution vs Confirmed Cases in MB', fontsize=20)

ax1 = axes[0].twinx()
ax1.plot('Time', 'Confirmed Cases', data=MB_CC, color='y', linestyle='--', linewidth=3, label='Confirmed Cases')

ax1.set_ylabel('Confirmed Cases', fontsize=15)
ax1.tick_params(direction='out', length=6, width=2, labelsize=10)
ax1.legend(loc='upper right')


for percentage in percentages:
    axes[1].plot('Time', percentage, data=MB_CC, marker='.', markersize=10)

axes[1].set_xlabel('Date', fontsize=15)
axes[1].set_ylabel('PPE Distribution %', fontsize=15)
axes[1].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
axes[1].tick_params(direction='out', length=6, width=2, labelsize=10)
axes[1].legend()
axes[1].set_title('PPE Distribution Percentage vs Confirmed Cases in MB', fontsize=20)

ax2 = axes[1].twinx()
ax2.plot('Time', 'Confirmed Cases', data=MB_CC, color='y', linestyle='--', linewidth=3, label='Confirmed Cases')

ax2.set_ylabel('Confirmed Cases', fontsize=15)
ax2.tick_params(direction='out', length=6, width=2, labelsize=10)
ax2.legend(loc='upper right')

plt.show()
In [23]:
pd.set_option("display.max_rows", None, "display.max_columns", None)


# Calculate the ratio of cumulative PPE data to cumulative confirmed cases data (Ratio 1)
for category in categories:
    MB_CC['{} Ratio 1'.format(category)] = MB_CC[category]/MB_CC['Confirmed Cases']
    
    
    
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 2)
# (Interval=2 weeks, one week before + the week itself)
MB_CC['Confirmed Cases(ma1)'] = MB_CC['Confirmed Cases'].rolling(window=2,center=False).mean()
MB_CC.iloc[0,-1] = (9060+12539) / 2
for category in categories:
    MB_CC['{} Ratio 2'.format(category)] = MB_CC[category]/MB_CC['Confirmed Cases(ma1)']





# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 3)
# (Interval=2 weeks, one week after + the week itself)
MB_CC['Confirmed Cases(ma2)'] = MB_CC['Confirmed Cases'].rolling(window=2,center=False).mean().shift(-1)
for category in categories:
    MB_CC['{} Ratio 3'.format(category)] = MB_CC[category]/MB_CC['Confirmed Cases(ma2)']

    
    
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 4)
# (Interval=3 weeks, one week before + one week after + the week itself)
MB_CC['Confirmed Cases(ma3)'] = MB_CC['Confirmed Cases'].rolling(window=3,center=False).mean().shift(-1)
MB_CC.iloc[0,-1] = (9060+12539+14476)/3
for category in categories:
    MB_CC['{} Ratio 4'.format(category)] = MB_CC[category]/MB_CC['Confirmed Cases(ma3)']

    
    
# Calculate the ratio of delta PPE data to delta confirmed cases data (Ratio 5)
for category in categories:
    MB_CC['{} Ratio 5'.format(category)] = MB_CC[category].diff()/MB_CC['Confirmed Cases'].diff()
    
    
    
# Calculate the ratio of delta PPE data to moving average delta confirmed cases data (Ratio 6)
for category in categories:
    MB_CC['{} Ratio 6'.format(category)] = MB_CC[category].diff()/MB_CC['Confirmed Cases'].diff().rolling(window=2,center=False).mean()
MB_CC
Out[23]:
Time Region N95s/KN95s Masks Gowns Gloves Ventilators Confirmed Cases N95s/KN95s % Masks % Gowns % Gloves % Ventilators % N95s/KN95s Ratio 1 Masks Ratio 1 Gowns Ratio 1 Gloves Ratio 1 Ventilators Ratio 1 Confirmed Cases(ma1) N95s/KN95s Ratio 2 Masks Ratio 2 Gowns Ratio 2 Gloves Ratio 2 Ventilators Ratio 2 Confirmed Cases(ma2) N95s/KN95s Ratio 3 Masks Ratio 3 Gowns Ratio 3 Gloves Ratio 3 Ventilators Ratio 3 Confirmed Cases(ma3) N95s/KN95s Ratio 4 Masks Ratio 4 Gowns Ratio 4 Gloves Ratio 4 Ventilators Ratio 4 N95s/KN95s Ratio 5 Masks Ratio 5 Gowns Ratio 5 Gloves Ratio 5 Ventilators Ratio 5 N95s/KN95s Ratio 6 Masks Ratio 6 Gowns Ratio 6 Gloves Ratio 6 Ventilators Ratio 6
44 2020-04-29 Metro Boston 94235.0 130800.0 23036.0 465692.0 204.0 12539.0 24.432138 26.723874 42.571751 58.967612 100.0 7.515352 10.431454 1.837148 37.139485 0.016269 10799.5 8.725867 12.111672 2.133062 43.121626 0.018890 13507.5 6.976495 9.683509 1.705423 34.476550 0.015103 12025.000000 7.836590 10.877339 1.915676 38.726985 0.016965 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
51 2020-05-06 Metro Boston 115642.0 146600.0 27956.0 535892.0 204.0 14476.0 29.982292 29.951987 51.664172 67.856591 100.0 7.988533 10.127107 1.931196 37.019342 0.014092 13507.5 8.561318 10.853230 2.069665 39.673663 0.015103 15031.5 7.693311 9.752852 1.859828 35.651266 0.013571 14200.666667 8.143420 10.323459 1.968640 37.737102 0.014366 11.051626 8.156944 2.540010 36.241611 0.0 NaN NaN NaN NaN NaN
58 2020-05-13 Metro Boston 127621.0 187600.0 31366.0 575792.0 204.0 15587.0 33.088066 38.328736 57.966033 72.908874 100.0 8.187656 12.035671 2.012318 36.940527 0.013088 15031.5 8.490237 12.480458 2.086685 38.305691 0.013571 16274.5 7.841777 11.527236 1.927310 35.380012 0.012535 15675.000000 8.141691 11.968102 2.001021 36.733142 0.013014 10.782178 36.903690 3.069307 35.913591 0.0 7.860236 26.902887 2.237533 26.181102 0.0
65 2020-05-20 Metro Boston 135101.0 217400.0 37846.0 626992.0 204.0 16962.0 35.027392 44.417203 69.941417 79.392004 100.0 7.964922 12.816885 2.231223 36.964509 0.012027 16274.5 8.301392 13.358321 2.325479 38.526038 0.012535 17279.0 7.818797 12.581747 2.190289 36.286359 0.011806 16715.000000 8.082620 13.006282 2.264194 37.510739 0.012205 5.440000 21.672727 4.712727 37.236364 0.0 6.017699 23.974256 5.213194 41.190668 0.0
72 2020-05-27 Metro Boston 157158.0 234150.0 43206.0 646892.0 204.0 17596.0 40.746070 47.839412 79.846981 81.911814 100.0 8.931462 13.307002 2.455444 36.763583 0.011594 17279.0 9.095318 13.551131 2.500492 37.438046 0.011806 17852.0 8.803383 13.116177 2.420233 36.236388 0.011427 17555.333333 8.952151 13.337827 2.461132 36.848745 0.011620 34.790221 26.419558 8.454259 31.388013 0.0 21.958188 16.674963 5.335988 19.810851 0.0
73 2020-06-03 Metro Boston 159715.0 238150.0 46156.0 676892.0 204.0 18108.0 41.409019 48.656655 85.298738 85.710523 100.0 8.820135 13.151646 2.548929 37.380826 0.011266 17852.0 8.946617 13.340242 2.585481 37.916872 0.011427 18253.0 8.750068 13.047170 2.528680 37.083877 0.011176 18034.000000 8.856327 13.205612 2.559388 37.534213 0.011312 4.994141 7.812500 5.761719 58.593750 0.0 4.462478 6.980803 5.148342 52.356021 0.0
74 2020-06-10 Metro Boston 161838.0 242350.0 47216.0 673292.0 204.0 18398.0 41.959445 49.514761 87.257674 85.254678 100.0 8.796500 13.172627 2.566366 36.595934 0.011088 18253.0 8.866378 13.277269 2.586753 36.886649 0.011176 18525.0 8.736194 13.082321 2.548772 36.345047 0.011012 18386.000000 8.802241 13.181225 2.568041 36.619819 0.011095 7.320690 14.482759 3.655172 -12.413793 0.0 5.294264 10.473815 2.643392 -8.977556 0.0
75 2020-06-17 Metro Boston 163040.0 246350.0 48436.0 678892.0 204.0 18652.0 42.271086 50.332005 89.512299 85.963770 100.0 8.741154 13.207699 2.596826 36.397813 0.010937 18525.0 8.801080 13.298246 2.614629 36.647341 0.011012 18728.5 8.705449 13.153750 2.586219 36.249139 0.010892 18618.333333 8.756960 13.231582 2.601522 36.463629 0.010957 4.732283 15.748031 4.803150 22.047244 0.0 4.419118 14.705882 4.485294 20.588235 0.0
76 2020-06-24 Metro Boston 163736.0 251350.0 48511.0 691942.0 204.0 18805.0 42.451536 51.353560 89.650903 87.616209 100.0 8.707046 13.366126 2.579686 36.795639 0.010848 18728.5 8.742612 13.420722 2.590223 36.945938 0.010892 18891.5 8.667178 13.304925 2.567874 36.627160 0.010799 18811.666667 8.703960 13.361389 2.578772 36.782599 0.010844 4.549020 32.679739 0.490196 85.294118 0.0 3.420147 24.570025 0.368550 64.127764 0.0
77 2020-07-01 Metro Boston 165116.0 256850.0 49011.0 701342.0 204.0 18978.0 42.809326 52.477270 90.574929 88.806471 100.0 8.700390 13.534092 2.582517 36.955527 0.010749 18891.5 8.740227 13.596062 2.594341 37.124739 0.010799 19082.0 8.652971 13.460329 2.568441 36.754114 0.010691 18989.666667 8.695045 13.525777 2.580930 36.932823 0.010743 7.976879 31.791908 2.890173 54.335260 0.0 8.466258 33.742331 3.067485 57.668712 0.0
78 2020-07-08 Metro Boston 168236.0 259850.0 49511.0 716342.0 204.0 19186.0 43.618243 53.090203 91.498956 90.705825 100.0 8.768685 13.543730 2.580580 37.336704 0.010633 19082.0 8.816476 13.617545 2.594644 37.540195 0.010691 19307.0 8.713731 13.458849 2.564407 37.102709 0.010566 19197.333333 8.763509 13.535734 2.579056 37.314662 0.010626 15.000000 14.423077 2.403846 72.115385 0.0 16.377953 15.748031 2.624672 78.740157 0.0
79 2020-07-15 Metro Boston 179881.0 294100.0 51711.0 720342.0 204.0 19428.0 46.637421 60.087854 95.564673 91.212320 100.0 9.258853 15.137945 2.661674 37.077517 0.010500 19307.0 9.316880 15.232817 2.678355 37.309888 0.010566 19532.5 9.209318 15.056956 2.647434 36.879150 0.010444 19417.000000 9.264098 15.146521 2.663182 37.098522 0.010506 48.119835 141.528926 9.090909 16.528926 0.0 51.755556 152.222222 9.777778 17.777778 0.0
80 2020-07-22 Metro Boston 345331.0 467100.0 54111.0 720342.0 204.0 19637.0 89.533343 95.433650 100.000000 91.212320 100.0 17.585731 23.786729 2.755563 36.682895 0.010389 19532.5 17.679816 23.913990 2.770306 36.879150 0.010444 19788.5 17.451095 23.604619 2.734467 36.402052 0.010309 19668.333333 17.557715 23.748835 2.751174 36.624456 0.010372 791.626794 827.751196 11.483254 0.000000 0.0 733.702882 767.184035 10.643016 0.000000 0.0
81 2020-07-29 Metro Boston 370891.0 475350.0 54111.0 720342.0 204.0 19940.0 96.160238 97.119215 100.000000 91.212320 100.0 18.600351 23.839017 2.713691 36.125476 0.010231 19788.5 18.742755 24.021528 2.734467 36.402052 0.010309 20194.0 18.366396 23.539170 2.679558 35.671090 0.010102 20008.333333 18.536826 23.757601 2.704423 36.002099 0.010196 84.356436 27.227723 0.000000 0.000000 0.0 99.843750 32.226562 0.000000 0.000000 0.0
82 2020-08-05 Metro Boston 371961.0 478450.0 54111.0 722342.0 204.0 20448.0 96.437655 97.752579 100.000000 91.465567 100.0 18.190581 23.398376 2.646273 35.325802 0.009977 20194.0 18.419382 23.692681 2.679558 35.770130 0.010102 20673.5 17.992164 23.143154 2.617409 34.940479 0.009868 20429.000000 18.207499 23.420138 2.648735 35.358657 0.009986 2.106299 6.102362 0.000000 3.937008 0.0 2.638718 7.644883 0.000000 4.932182 0.0
83 2020-08-12 Metro Boston 371961.0 478450.0 54111.0 785742.0 204.0 20899.0 96.437655 97.752579 100.000000 99.493505 100.0 17.798029 22.893440 2.589167 37.597110 0.009761 20673.5 17.992164 23.143154 2.617409 38.007207 0.009868 21146.0 17.590135 22.626029 2.558924 37.157949 0.009647 20913.333333 17.785830 22.877749 2.587392 37.571342 0.009755 0.000000 0.000000 0.000000 140.576497 0.0 0.000000 0.000000 0.000000 132.221064 0.0
84 2020-08-19 Metro Boston 372901.0 478450.0 54111.0 785742.0 204.0 21393.0 96.681367 97.752579 100.000000 99.493505 100.0 17.430982 22.364792 2.529379 36.728930 0.009536 21146.0 17.634588 22.626029 2.558924 37.157949 0.009647 21669.5 17.208565 22.079420 2.497104 36.260274 0.009414 21412.666667 17.414972 22.344251 2.527056 36.695196 0.009527 1.902834 0.000000 0.000000 0.000000 0.0 1.989418 0.000000 0.000000 0.000000 0.0
85 2020-08-26 Metro Boston 384201.0 478450.0 54111.0 789742.0 204.0 21946.0 99.611098 97.752579 100.000000 100.000000 100.0 17.506653 21.801239 2.465643 35.985692 0.009296 21669.5 17.730035 22.079420 2.497104 36.444865 0.009414 22227.0 17.285329 21.525622 2.434472 35.530751 0.009178 21949.000000 17.504260 21.798260 2.465306 35.980774 0.009294 20.433996 0.000000 0.000000 7.233273 0.0 21.585482 0.000000 0.000000 7.640879 0.0
86 2020-09-02 Metro Boston 384701.0 489450.0 54111.0 789742.0 204.0 22508.0 99.740732 100.000000 100.000000 100.000000 100.0 17.091745 21.745602 2.404079 35.087169 0.009063 22227.0 17.307824 22.020516 2.434472 35.530751 0.009178 22669.5 16.969982 21.590684 2.386952 34.837204 0.008999 22428.333333 17.152456 21.822843 2.412618 35.211801 0.009096 0.889680 19.572954 0.000000 0.000000 0.0 0.896861 19.730942 0.000000 0.000000 0.0
87 2020-09-09 Metro Boston 385701.0 489450.0 54111.0 789742.0 204.0 22831.0 100.000000 100.000000 100.000000 100.000000 100.0 16.893741 21.437957 2.370067 34.590776 0.008935 22669.5 17.014094 21.590684 2.386952 34.837204 0.008999 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 3.095975 0.000000 0.000000 0.000000 0.0 2.259887 0.000000 0.000000 0.000000 0.0
In [24]:
# Plot the Ratio of PPE to Confirmed Cases

RATIO1 = []
RATIO2 = []
RATIO3 = []
RATIO4 = []
RATIO5 = []
RATIO6 = []
RATIOS = [RATIO1, RATIO2, RATIO3, RATIO4, RATIO5, RATIO6]
for RATIO in RATIOS:
    for category in categories:
        RATIO.append('{} Ratio {}'.format(category, RATIOS.index(RATIO)+1))

fig, axes = plt.subplots(6,1,figsize=(15,48))
color = ['b', 'g', 'r', 'c', 'm']


for RATIO in RATIOS:
    for category in categories:
        axes[RATIOS.index(RATIO)].plot('Time', category, data=MB_CC, color=color[categories.index(category)], linewidth=3, label=category, marker='.', markersize=12)
        axes[RATIOS.index(RATIO)].set_xlabel('Date', fontsize=15)
        axes[RATIOS.index(RATIO)].set_ylabel('The number of PPE', fontsize=15)
        axes[RATIOS.index(RATIO)].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
        axes[RATIOS.index(RATIO)].legend(loc='best')
        axes[RATIOS.index(RATIO)].set_title('The Ratio of PPE Dstribution to Confirmed Cases in Metro Boston', fontsize=20)
    ax1 = axes[RATIOS.index(RATIO)].twinx()
    for ratio in RATIO:
        ax1.plot('Time', ratio, data=MB_CC, color=color[RATIO.index(ratio)], linestyle='--', linewidth=3, label=ratio, marker='^', markersize=8)
        ax1.set_ylabel('Ratio', fontsize=15)
        ax1.legend(loc='best')
plt.show()
In [25]:
for category in categories:
    MB_CC['{} delta'.format(category)] = MB_CC[category].diff()
    MB_CC['Confirmed Cases delta'] = MB_CC['Confirmed Cases'].diff()

fig, axes = plt.subplots(2, 3, figsize=(25,15))

for ax, category in zip(axes.flatten(), categories):
    sns.regplot('Confirmed Cases', category, data=MB_CC, ax=ax)
    ax.set_xlabel('Confirmed Cases', fontsize=15)
    ax.set_ylabel(category, fontsize=15)
fig.delaxes(axes[1,2])
fig.suptitle('Regression Plot (Cumulative vs Cumulative)', fontsize=25)

fig1, axes1 = plt.subplots(2, 3, figsize=(25,15))

for ax, category in zip(axes1.flatten(), categories):
    sns.regplot('Confirmed Cases delta', category + ' delta', data=MB_CC, ax=ax)
    ax.set_xlabel('Confirmed Cases', fontsize=15)
    ax.set_ylabel(category, fontsize=15)
fig1.delaxes(axes1[1,2])
fig1.suptitle('Regression Plot (Delta vs Delta)', fontsize=25)
Out[25]:
Text(0.5, 0.98, 'Regression Plot (Delta vs Delta)')
In [26]:
import statsmodels.api as sm
Y = [pd.DataFrame] * 5
X = [pd.DataFrame] * 5
for category in categories:
    Y[categories.index(category)] = MB_CC[category]
    X[categories.index(category)] = MB_CC['Confirmed Cases']
    X[categories.index(category)] = sm.add_constant(X[categories.index(category)])
    model = sm.OLS(Y[categories.index(category)], X[categories.index(category)])
    results = model.fit()
    print(results.summary())
                            OLS Regression Results                            
==============================================================================
Dep. Variable:             N95s/KN95s   R-squared:                       0.706
Model:                            OLS   Adj. R-squared:                  0.689
Method:                 Least Squares   F-statistic:                     43.13
Date:                Sun, 13 Sep 2020   Prob (F-statistic):           3.60e-06
Time:                        20:58:22   Log-Likelihood:                -248.62
No. Observations:                  20   AIC:                             501.2
Df Residuals:                      18   BIC:                             503.2
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const           -4.578e+05   1.07e+05     -4.276      0.000   -6.83e+05   -2.33e+05
Confirmed Cases    36.8346      5.609      6.567      0.000      25.051      48.618
==============================================================================
Omnibus:                        7.017   Durbin-Watson:                   0.439
Prob(Omnibus):                  0.030   Jarque-Bera (JB):                1.797
Skew:                           0.102   Prob(JB):                        0.407
Kurtosis:                       1.546   Cond. No.                     1.43e+05
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 1.43e+05. This might indicate that there are
strong multicollinearity or other numerical problems.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:                  Masks   R-squared:                       0.773
Model:                            OLS   Adj. R-squared:                  0.761
Method:                 Least Squares   F-statistic:                     61.34
Date:                Sun, 13 Sep 2020   Prob (F-statistic):           3.31e-07
Time:                        20:58:22   Log-Likelihood:                -248.96
No. Observations:                  20   AIC:                             501.9
Df Residuals:                      18   BIC:                             503.9
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const           -5.181e+05   1.09e+05     -4.758      0.000   -7.47e+05   -2.89e+05
Confirmed Cases    44.6811      5.705      7.832      0.000      32.695      56.667
==============================================================================
Omnibus:                        3.450   Durbin-Watson:                   0.479
Prob(Omnibus):                  0.178   Jarque-Bera (JB):                1.651
Skew:                           0.374   Prob(JB):                        0.438
Kurtosis:                       1.808   Cond. No.                     1.43e+05
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 1.43e+05. This might indicate that there are
strong multicollinearity or other numerical problems.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:                  Gowns   R-squared:                       0.889
Model:                            OLS   Adj. R-squared:                  0.882
Method:                 Least Squares   F-statistic:                     143.6
Date:                Sun, 13 Sep 2020   Prob (F-statistic):           5.16e-10
Time:                        20:58:22   Log-Likelihood:                -189.14
No. Observations:                  20   AIC:                             382.3
Df Residuals:                      18   BIC:                             384.3
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const            -1.81e+04   5468.315     -3.310      0.004   -2.96e+04   -6612.584
Confirmed Cases     3.4333      0.287     11.984      0.000       2.831       4.035
==============================================================================
Omnibus:                        2.360   Durbin-Watson:                   0.213
Prob(Omnibus):                  0.307   Jarque-Bera (JB):                1.563
Skew:                          -0.461   Prob(JB):                        0.458
Kurtosis:                       1.987   Cond. No.                     1.43e+05
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 1.43e+05. This might indicate that there are
strong multicollinearity or other numerical problems.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:                 Gloves   R-squared:                       0.974
Model:                            OLS   Adj. R-squared:                  0.973
Method:                 Least Squares   F-statistic:                     680.2
Date:                Sun, 13 Sep 2020   Prob (F-statistic):           9.45e-16
Time:                        20:58:22   Log-Likelihood:                -218.93
No. Observations:                  20   AIC:                             441.9
Df Residuals:                      18   BIC:                             443.9
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const            6.376e+04   2.43e+04      2.629      0.017    1.28e+04    1.15e+05
Confirmed Cases    33.1437      1.271     26.080      0.000      30.474      35.814
==============================================================================
Omnibus:                        0.549   Durbin-Watson:                   1.124
Prob(Omnibus):                  0.760   Jarque-Bera (JB):                0.126
Skew:                          -0.195   Prob(JB):                        0.939
Kurtosis:                       2.993   Cond. No.                     1.43e+05
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 1.43e+05. This might indicate that there are
strong multicollinearity or other numerical problems.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:            Ventilators   R-squared:                        -inf
Model:                            OLS   Adj. R-squared:                   -inf
Method:                 Least Squares   F-statistic:                    -18.00
Date:                Sun, 13 Sep 2020   Prob (F-statistic):               1.00
Time:                        20:58:22   Log-Likelihood:                 587.34
No. Observations:                  20   AIC:                            -1171.
Df Residuals:                      18   BIC:                            -1169.
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const             204.0000   7.53e-14   2.71e+15      0.000     204.000     204.000
Confirmed Cases  6.939e-18   3.95e-18      1.759      0.096   -1.35e-18    1.52e-17
==============================================================================
Omnibus:                        2.366   Durbin-Watson:                   0.067
Prob(Omnibus):                  0.306   Jarque-Bera (JB):                1.133
Skew:                           0.566   Prob(JB):                        0.567
Kurtosis:                       3.279   Cond. No.                     1.43e+05
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 1.43e+05. This might indicate that there are
strong multicollinearity or other numerical problems.







Central Massachusetts

In [27]:
CM = df.loc[df['Region']=='Central Massachusetts']
CM_CC = CM.dropna()
categories = ['N95s/KN95s', 'Masks', 'Gowns', 'Gloves', 'Ventilators']
for category in categories:
    CM_CC['{} %'.format(category)] = CM_CC[category]/CM_CC[category].iloc[-1] * 100
    
# fig, axes = plt.subplots(2, 3, figsize=(25,15))
# for ax, category in zip(axes.flatten(), categories):
#     sns.distplot(CM_CC[category].diff(), ax=ax)
#     ax.set_xlabel(category, fontsize=15)
# fig.delaxes(axes[1,2])
CM_CC
Out[27]:
Time Region N95s/KN95s Masks Gowns Gloves Ventilators Confirmed Cases N95s/KN95s % Masks % Gowns % Gloves % Ventilators %
0 2020-04-29 Central Massachusetts 138350.0 263767.0 43293.0 454250.0 79.0 5363.0 12.562894 19.186306 45.118494 41.951345 95.180723
7 2020-05-06 Central Massachusetts 170144.0 292767.0 46627.0 794650.0 79.0 7056.0 15.449953 21.295754 48.593076 73.388302 95.180723
14 2020-05-13 Central Massachusetts 184220.0 350367.0 54390.0 858250.0 79.0 8335.0 16.728127 25.485555 56.683411 79.261952 95.180723
21 2020-05-20 Central Massachusetts 191280.0 364617.0 60380.0 889350.0 79.0 9857.0 17.369211 26.522094 62.925985 82.134130 95.180723
28 2020-05-27 Central Massachusetts 220534.0 392367.0 69922.0 905950.0 83.0 10743.0 20.025625 28.540618 72.870334 83.667189 100.000000
29 2020-06-03 Central Massachusetts 239254.0 420667.0 75489.0 975650.0 83.0 11296.0 21.725498 30.599149 78.672072 90.104193 100.000000
30 2020-06-10 Central Massachusetts 246659.0 456767.0 79129.0 986150.0 83.0 11641.0 22.397910 33.225048 82.465556 91.073899 100.000000
31 2020-06-17 Central Massachusetts 245449.0 462867.0 83339.0 1003150.0 83.0 11827.0 22.288036 33.668760 86.853075 92.643900 100.000000
32 2020-06-24 Central Massachusetts 246509.0 465367.0 84339.0 1007650.0 83.0 12001.0 22.384289 33.850609 87.895241 93.059488 100.000000
33 2020-07-01 Central Massachusetts 248049.0 472067.0 88739.0 1013850.0 83.0 12148.0 22.524129 34.337964 92.480772 93.632077 100.000000
34 2020-07-08 Central Massachusetts 249229.0 474167.0 90249.0 1015450.0 83.0 12296.0 22.631279 34.490717 94.054443 93.779842 100.000000
35 2020-07-15 Central Massachusetts 254659.0 493317.0 93149.0 1026050.0 83.0 12409.0 23.124351 35.883681 97.076724 94.758783 100.000000
36 2020-07-22 Central Massachusetts 425969.0 687317.0 93149.0 1027050.0 83.0 12541.0 38.680183 49.995163 97.076724 94.851136 100.000000
37 2020-07-29 Central Massachusetts 546539.0 814117.0 93179.0 1027650.0 83.0 12726.0 49.628561 59.218544 97.107989 94.906548 100.000000
38 2020-08-05 Central Massachusetts 549419.0 820117.0 95779.0 1037650.0 83.0 12968.0 49.890080 59.654982 99.817621 95.830078 100.000000
39 2020-08-12 Central Massachusetts 864179.0 1141467.0 95779.0 1067250.0 83.0 13138.0 78.471913 83.029852 99.817621 98.563726 100.000000
40 2020-08-19 Central Massachusetts 1088389.0 1371917.0 95829.0 1071930.0 83.0 13317.0 98.831338 99.792692 99.869729 98.995938 100.000000
41 2020-08-26 Central Massachusetts 1091409.0 1374017.0 95904.0 1072002.0 83.0 13513.0 99.105569 99.945445 99.947892 99.002588 100.000000
42 2020-09-02 Central Massachusetts 1091759.0 1374767.0 95904.0 1076802.0 83.0 13705.0 99.137351 100.000000 99.947892 99.445882 100.000000
43 2020-09-09 Central Massachusetts 1101259.0 1374767.0 95954.0 1082802.0 83.0 13906.0 100.000000 100.000000 100.000000 100.000000 100.000000
In [28]:
# Confirmed cases vs PPE distribution
fig, axes = plt.subplots(2,1,figsize=(15,14))

percentages = ['N95s/KN95s %', 'Masks %', 'Gowns %', 'Gloves %', 'Ventilators %']

for category in categories:
    axes[0].plot('Time', category, data=CM_CC, marker='.', markersize=10)

axes[0].set_xlabel('Date', fontsize=15)
axes[0].set_ylabel('The Number of PPE Distribution', fontsize=15)
axes[0].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
axes[0].tick_params(direction='out', length=6, width=2, labelsize=10)
axes[0].legend()
axes[0].set_title('PPE Distribution vs Confirmed Cases in CM', fontsize=20)

ax1 = axes[0].twinx()
ax1.plot('Time', 'Confirmed Cases', data=CM_CC, color='y', linestyle='--', linewidth=3, label='Confirmed Cases')

ax1.set_ylabel('Confirmed Cases', fontsize=15)
ax1.tick_params(direction='out', length=6, width=2, labelsize=10)
ax1.legend(loc='upper right')


for percentage in percentages:
    axes[1].plot('Time', percentage, data=CM_CC, marker='.', markersize=10)

axes[1].set_xlabel('Date', fontsize=15)
axes[1].set_ylabel('PPE Distribution %', fontsize=15)
axes[1].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
axes[1].tick_params(direction='out', length=6, width=2, labelsize=10)
axes[1].legend()
axes[1].set_title('PPE Distribution Percentage vs Confirmed Cases in CM', fontsize=20)

ax2 = axes[1].twinx()
ax2.plot('Time', 'Confirmed Cases', data=CM_CC, color='y', linestyle='--', linewidth=3, label='Confirmed Cases')

ax2.set_ylabel('Confirmed Cases', fontsize=15)
ax2.tick_params(direction='out', length=6, width=2, labelsize=10)
ax2.legend(loc='upper right')

plt.show()
In [29]:
pd.set_option("display.max_rows", None, "display.max_columns", None)


# Calculate the ratio of cumulative PPE data to cumulative confirmed cases data (Ratio 1)
for category in categories:
    CM_CC['{} Ratio 1'.format(category)] = CM_CC[category]/CM_CC['Confirmed Cases']
    
    
    
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 2)
# (Interval=2 weeks, one week before + the week itself)
CM_CC['Confirmed Cases(ma1)'] = CM_CC['Confirmed Cases'].rolling(window=2,center=False).mean()
CM_CC.iloc[0,-1] = (3474+5363) / 2
for category in categories:
    CM_CC['{} Ratio 2'.format(category)] = CM_CC[category]/CM_CC['Confirmed Cases(ma1)']





# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 3)
# (Interval=2 weeks, one week after + the week itself)
CM_CC['Confirmed Cases(ma2)'] = CM_CC['Confirmed Cases'].rolling(window=2,center=False).mean().shift(-1)
for category in categories:
    CM_CC['{} Ratio 3'.format(category)] = CM_CC[category]/CM_CC['Confirmed Cases(ma2)']

    
    
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 4)
# (Interval=3 weeks, one week before + one week after + the week itself)
CM_CC['Confirmed Cases(ma3)'] = CM_CC['Confirmed Cases'].rolling(window=3,center=False).mean().shift(-1)
CM_CC.iloc[0,-1] = (3474+5363+7056)/3
for category in categories:
    CM_CC['{} Ratio 4'.format(category)] = CM_CC[category]/CM_CC['Confirmed Cases(ma3)']

    
    
# Calculate the ratio of delta PPE data to delta confirmed cases data (Ratio 5)
for category in categories:
    CM_CC['{} Ratio 5'.format(category)] = CM_CC[category].diff()/CM_CC['Confirmed Cases'].diff()
    
    
    
# Calculate the ratio of delta PPE data to moving average delta confirmed cases data (Ratio 6)
for category in categories:
    CM_CC['{} Ratio 6'.format(category)] = CM_CC[category].diff()/CM_CC['Confirmed Cases'].diff().rolling(window=2,center=False).mean()
CM_CC
Out[29]:
Time Region N95s/KN95s Masks Gowns Gloves Ventilators Confirmed Cases N95s/KN95s % Masks % Gowns % Gloves % Ventilators % N95s/KN95s Ratio 1 Masks Ratio 1 Gowns Ratio 1 Gloves Ratio 1 Ventilators Ratio 1 Confirmed Cases(ma1) N95s/KN95s Ratio 2 Masks Ratio 2 Gowns Ratio 2 Gloves Ratio 2 Ventilators Ratio 2 Confirmed Cases(ma2) N95s/KN95s Ratio 3 Masks Ratio 3 Gowns Ratio 3 Gloves Ratio 3 Ventilators Ratio 3 Confirmed Cases(ma3) N95s/KN95s Ratio 4 Masks Ratio 4 Gowns Ratio 4 Gloves Ratio 4 Ventilators Ratio 4 N95s/KN95s Ratio 5 Masks Ratio 5 Gowns Ratio 5 Gloves Ratio 5 Ventilators Ratio 5 N95s/KN95s Ratio 6 Masks Ratio 6 Gowns Ratio 6 Gloves Ratio 6 Ventilators Ratio 6
0 2020-04-29 Central Massachusetts 138350.0 263767.0 43293.0 454250.0 79.0 5363.0 12.562894 19.186306 45.118494 41.951345 95.180723 25.797128 49.182734 8.072534 84.700727 0.014731 4418.5 31.311531 59.696051 9.798122 102.806382 0.017879 6209.5 22.280377 42.477977 6.972059 73.154038 0.012722 5297.666667 26.115271 49.789278 8.172088 85.745297 0.014912 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
7 2020-05-06 Central Massachusetts 170144.0 292767.0 46627.0 794650.0 79.0 7056.0 15.449953 21.295754 48.593076 73.388302 95.180723 24.113379 41.491922 6.608135 112.620465 0.011196 6209.5 27.400596 47.148241 7.508978 127.973267 0.012722 7695.5 22.109545 38.043922 6.058996 103.261646 0.010266 6918.000000 24.594391 42.319601 6.739954 114.867014 0.011419 18.779681 17.129356 1.969285 201.063201 0.000000 NaN NaN NaN NaN NaN
14 2020-05-13 Central Massachusetts 184220.0 350367.0 54390.0 858250.0 79.0 8335.0 16.728127 25.485555 56.683411 79.261952 95.180723 22.101980 42.035633 6.525495 102.969406 0.009478 7695.5 23.938665 45.528816 7.067767 111.526217 0.010266 9096.0 20.252858 38.518799 5.979551 94.354661 0.008685 8416.000000 21.889259 41.631060 6.462690 101.978375 0.009387 11.005473 45.035184 6.069586 49.726349 0.000000 9.472409 38.761777 5.224092 42.799462 0.000000
21 2020-05-20 Central Massachusetts 191280.0 364617.0 60380.0 889350.0 79.0 9857.0 17.369211 26.522094 62.925985 82.134130 95.180723 19.405499 36.990667 6.125596 90.225221 0.008015 9096.0 21.029024 40.085422 6.638083 97.773747 0.008685 10300.0 18.570874 35.399709 5.862136 86.344660 0.007670 9645.000000 19.832037 37.803733 6.260238 92.208398 0.008191 4.638633 9.362681 3.935611 20.433640 0.000000 5.041057 10.174938 4.277044 22.206355 0.000000
28 2020-05-27 Central Massachusetts 220534.0 392367.0 69922.0 905950.0 83.0 10743.0 20.025625 28.540618 72.870334 83.667189 100.000000 20.528158 36.523038 6.508610 84.329331 0.007726 10300.0 21.411068 38.093883 6.788544 87.956311 0.008058 11019.5 20.013068 35.606606 6.345297 82.213349 0.007532 10632.000000 20.742476 36.904345 6.576561 85.209744 0.007807 33.018059 31.320542 10.769752 18.735892 0.004515 24.297342 23.048173 7.925249 13.787375 0.003322
29 2020-06-03 Central Massachusetts 239254.0 420667.0 75489.0 975650.0 83.0 11296.0 21.725498 30.599149 78.672072 90.104193 100.000000 21.180418 37.240351 6.682808 86.371282 0.007348 11019.5 21.711874 38.174781 6.850492 88.538500 0.007532 11468.5 20.861839 36.680211 6.582291 85.072154 0.007237 11226.666667 21.311223 37.470338 6.724080 86.904691 0.007393 33.851718 51.175407 10.066908 126.039783 0.000000 26.018068 39.332870 7.737318 96.872828 0.000000
30 2020-06-10 Central Massachusetts 246659.0 456767.0 79129.0 986150.0 83.0 11641.0 22.397910 33.225048 82.465556 91.073899 100.000000 21.188815 39.237780 6.797440 84.713513 0.007130 11468.5 21.507521 39.827964 6.899682 85.987705 0.007237 11734.0 21.020879 38.926794 6.743566 84.042100 0.007073 11588.000000 21.285727 39.417242 6.828530 85.100967 0.007163 21.463768 104.637681 10.550725 30.434783 0.000000 16.492205 80.400891 8.106904 23.385301 0.000000
31 2020-06-17 Central Massachusetts 245449.0 462867.0 83339.0 1003150.0 83.0 11827.0 22.288036 33.668760 86.853075 92.643900 100.000000 20.753276 39.136467 7.046504 84.818635 0.007018 11734.0 20.917760 39.446651 7.102352 85.490881 0.007073 11914.0 20.601729 38.850680 6.995048 84.199261 0.006967 11823.000000 20.760298 39.149708 7.048888 84.847331 0.007020 -6.505376 32.795699 22.634409 91.397849 0.000000 -4.557439 22.975518 15.856874 64.030132 0.000000
32 2020-06-24 Central Massachusetts 246509.0 465367.0 84339.0 1007650.0 83.0 12001.0 22.384289 33.850609 87.895241 93.059488 100.000000 20.540705 38.777352 7.027664 83.963836 0.006916 11914.0 20.690700 39.060517 7.078983 84.576968 0.006967 12074.5 20.415669 38.541306 6.984886 83.452731 0.006874 11992.000000 20.556121 38.806454 7.032939 84.026851 0.006921 6.091954 14.367816 5.747126 25.862069 0.000000 5.888889 13.888889 5.555556 25.000000 0.000000
33 2020-07-01 Central Massachusetts 248049.0 472067.0 88739.0 1013850.0 83.0 12148.0 22.524129 34.337964 92.480772 93.632077 100.000000 20.418917 38.859648 7.304824 83.458182 0.006832 12074.5 20.543211 39.096194 7.349290 83.966210 0.006874 12222.0 20.295287 38.624366 7.260596 82.952872 0.006791 12148.333333 20.418356 38.858581 7.304623 83.455892 0.006832 10.476190 45.578231 29.931973 42.176871 0.000000 9.595016 41.744548 27.414330 38.629283 0.000000
34 2020-07-08 Central Massachusetts 249229.0 474167.0 90249.0 1015450.0 83.0 12296.0 22.631279 34.490717 94.054443 93.779842 100.000000 20.269112 38.562703 7.339704 82.583767 0.006750 12222.0 20.391834 38.796187 7.384143 83.083783 0.006791 12352.5 20.176402 38.386319 7.306132 82.206031 0.006719 12284.333333 20.288362 38.599327 7.346675 82.662198 0.006757 7.972973 14.189189 10.202703 10.810811 0.000000 8.000000 14.237288 10.237288 10.847458 0.000000
35 2020-07-15 Central Massachusetts 254659.0 493317.0 93149.0 1026050.0 83.0 12409.0 23.124351 35.883681 97.076724 94.758783 100.000000 20.522121 39.754775 7.506568 82.685954 0.006689 12352.5 20.615989 39.936612 7.540903 83.064157 0.006719 12475.0 20.413547 39.544449 7.466854 82.248497 0.006653 12415.333333 20.511652 39.734495 7.502739 82.643774 0.006685 48.053097 169.469027 25.663717 93.805310 0.000000 41.609195 146.743295 22.222222 81.226054 0.000000
36 2020-07-22 Central Massachusetts 425969.0 687317.0 93149.0 1027050.0 83.0 12541.0 38.680183 49.995163 97.076724 94.851136 100.000000 33.966111 54.805598 7.427558 81.895383 0.006618 12475.0 34.145812 55.095551 7.466854 82.328657 0.006653 12633.5 33.717418 54.404322 7.373174 81.295761 0.006570 12558.666667 33.918330 54.728501 7.417109 81.780178 0.006609 1297.803030 1469.696970 0.000000 7.575758 0.000000 1398.448980 1583.673469 0.000000 8.163265 0.000000
37 2020-07-29 Central Massachusetts 546539.0 814117.0 93179.0 1027650.0 83.0 12726.0 49.628561 59.218544 97.107989 94.906548 100.000000 42.946645 63.972733 7.321939 80.752004 0.006522 12633.5 43.261092 64.441129 7.375549 81.343254 0.006570 12847.0 42.542150 63.370203 7.252977 79.991438 0.006461 12745.000000 42.882621 63.877364 7.311024 80.631620 0.006512 651.729730 685.405405 0.162162 3.243243 0.000000 760.694006 800.000000 0.189274 3.785489 0.000000
38 2020-08-05 Central Massachusetts 549419.0 820117.0 95779.0 1037650.0 83.0 12968.0 49.890080 59.654982 99.817621 95.830078 100.000000 42.367289 63.241595 7.385796 80.016194 0.006400 12847.0 42.766327 63.837238 7.455359 80.769830 0.006461 13053.0 42.091397 62.829771 7.337700 79.495135 0.006359 12944.000000 42.445844 63.358854 7.399490 80.164555 0.006412 11.900826 24.793388 10.743802 41.322314 0.000000 13.489461 28.103044 12.177986 46.838407 0.000000
39 2020-08-12 Central Massachusetts 864179.0 1141467.0 95779.0 1067250.0 83.0 13138.0 78.471913 83.029852 99.817621 98.563726 100.000000 65.777059 86.882859 7.290227 81.233826 0.006318 13053.0 66.205393 87.448632 7.337700 81.762813 0.006359 13227.5 65.331998 86.294991 7.240900 80.684181 0.006275 13141.000000 65.762042 86.863024 7.288563 81.215280 0.006316 1851.529412 1890.294118 0.000000 174.117647 0.000000 1527.961165 1559.951456 0.000000 143.689320 0.000000
40 2020-08-19 Central Massachusetts 1088389.0 1371917.0 95829.0 1071930.0 83.0 13317.0 98.831338 99.792692 99.869729 98.995938 100.000000 81.729293 103.019974 7.195990 80.493354 0.006233 13227.5 82.282291 103.717029 7.244680 81.037989 0.006275 13415.0 81.132240 102.267387 7.143422 79.905330 0.006187 13322.666667 81.694531 102.976156 7.192929 80.459117 0.006230 1252.569832 1287.430168 0.279330 26.145251 0.000000 1284.871060 1320.630372 0.286533 26.819484 0.000000
41 2020-08-26 Central Massachusetts 1091409.0 1374017.0 95904.0 1072002.0 83.0 13513.0 99.105569 99.945445 99.947892 99.002588 100.000000 80.767335 101.681122 7.097166 79.331163 0.006142 13415.0 81.357361 102.423928 7.149012 79.910697 0.006187 13609.0 80.197590 100.963847 7.047101 78.771548 0.006099 13511.666667 80.775305 101.691156 7.097866 79.338991 0.006143 15.408163 10.714286 0.382653 0.367347 0.000000 16.106667 11.200000 0.400000 0.384000 0.000000
42 2020-09-02 Central Massachusetts 1091759.0 1374767.0 95904.0 1076802.0 83.0 13705.0 99.137351 100.000000 99.947892 99.445882 100.000000 79.661364 100.311346 6.997738 78.570011 0.006056 13609.0 80.223308 101.018958 7.047101 79.124256 0.006099 13805.5 79.081453 99.581109 6.946797 77.998044 0.006012 13708.000000 79.643931 100.289393 6.996207 78.552816 0.006055 1.822917 3.906250 0.000000 25.000000 0.000000 1.804124 3.865979 0.000000 24.742268 0.000000
43 2020-09-09 Central Massachusetts 1101259.0 1374767.0 95954.0 1082802.0 83.0 13906.0 100.000000 100.000000 100.000000 100.000000 100.000000 79.193082 98.861427 6.900187 77.865813 0.005969 13805.5 79.769585 99.581109 6.950418 78.432654 0.006012 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 47.263682 0.000000 0.248756 29.850746 0.000000 48.346056 0.000000 0.254453 30.534351 0.000000
In [30]:
# Plot the Ratio of PPE to Confirmed Cases

RATIO1 = []
RATIO2 = []
RATIO3 = []
RATIO4 = []
RATIO5 = []
RATIO6 = []
RATIOS = [RATIO1, RATIO2, RATIO3, RATIO4, RATIO5, RATIO6]
for RATIO in RATIOS:
    for category in categories:
        RATIO.append('{} Ratio {}'.format(category, RATIOS.index(RATIO)+1))

fig, axes = plt.subplots(6,1,figsize=(15,48))
color = ['b', 'g', 'r', 'c', 'm']


for RATIO in RATIOS:
    for category in categories:
        axes[RATIOS.index(RATIO)].plot('Time', category, data=CM_CC, color=color[categories.index(category)], linewidth=3, label=category, marker='.', markersize=12)
        axes[RATIOS.index(RATIO)].set_xlabel('Date', fontsize=15)
        axes[RATIOS.index(RATIO)].set_ylabel('The number of PPE', fontsize=15)
        axes[RATIOS.index(RATIO)].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
        axes[RATIOS.index(RATIO)].legend(loc='best')
        axes[RATIOS.index(RATIO)].set_title('The Ratio of PPE Dstribution to Confirmed Cases in Central Massachusetts', fontsize=20)
    ax1 = axes[RATIOS.index(RATIO)].twinx()
    for ratio in RATIO:
        ax1.plot('Time', ratio, data=CM_CC, color=color[RATIO.index(ratio)], linestyle='--', linewidth=3, label=ratio, marker='^', markersize=8)
        ax1.set_ylabel('Ratio', fontsize=15)
        ax1.legend(loc='best')
plt.show()
In [31]:
for category in categories:
    CM_CC['{} delta'.format(category)] = CM_CC[category].diff()
    CM_CC['Confirmed Cases delta'] = CM_CC['Confirmed Cases'].diff()

fig, axes = plt.subplots(2, 3, figsize=(25,15))

for ax, category in zip(axes.flatten(), categories):
    sns.regplot('Confirmed Cases', category, data=CM_CC, ax=ax)
    ax.set_xlabel('Confirmed Cases', fontsize=15)
    ax.set_ylabel(category, fontsize=15)
fig.delaxes(axes[1,2])
fig.suptitle('Regression Plot (Cumulative vs Cumulative)', fontsize=25)

fig1, axes1 = plt.subplots(2, 3, figsize=(25,15))

for ax, category in zip(axes1.flatten(), categories):
    sns.regplot('Confirmed Cases delta', category + ' delta', data=CM_CC, ax=ax)
    ax.set_xlabel('Confirmed Cases', fontsize=15)
    ax.set_ylabel(category, fontsize=15)
fig1.delaxes(axes1[1,2])
fig1.suptitle('Regression Plot (Delta vs Delta)', fontsize=25)
Out[31]:
Text(0.5, 0.98, 'Regression Plot (Delta vs Delta)')
In [32]:
import statsmodels.api as sm
Y = [pd.DataFrame] * 5
X = [pd.DataFrame] * 5
for category in categories:
    Y[categories.index(category)] = CM_CC[category]
    X[categories.index(category)] = CM_CC['Confirmed Cases']
    X[categories.index(category)] = sm.add_constant(X[categories.index(category)])
    model = sm.OLS(Y[categories.index(category)], X[categories.index(category)])
    results = model.fit()
    print(results.summary())
                            OLS Regression Results                            
==============================================================================
Dep. Variable:             N95s/KN95s   R-squared:                       0.433
Model:                            OLS   Adj. R-squared:                  0.402
Method:                 Least Squares   F-statistic:                     13.76
Date:                Sun, 13 Sep 2020   Prob (F-statistic):            0.00160
Time:                        20:58:28   Log-Likelihood:                -278.18
No. Observations:                  20   AIC:                             560.4
Df Residuals:                      18   BIC:                             562.4
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const           -7.393e+05   3.32e+05     -2.228      0.039   -1.44e+06   -4.21e+04
Confirmed Cases   104.7657     28.239      3.710      0.002      45.437     164.094
==============================================================================
Omnibus:                        6.118   Durbin-Watson:                   0.165
Prob(Omnibus):                  0.047   Jarque-Bera (JB):                2.252
Skew:                           0.460   Prob(JB):                        0.324
Kurtosis:                       1.638   Cond. No.                     6.22e+04
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 6.22e+04. This might indicate that there are
strong multicollinearity or other numerical problems.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:                  Masks   R-squared:                       0.502
Model:                            OLS   Adj. R-squared:                  0.474
Method:                 Least Squares   F-statistic:                     18.15
Date:                Sun, 13 Sep 2020   Prob (F-statistic):           0.000471
Time:                        20:58:28   Log-Likelihood:                -279.13
No. Observations:                  20   AIC:                             562.3
Df Residuals:                      18   BIC:                             564.3
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const           -7.619e+05   3.48e+05     -2.190      0.042   -1.49e+06   -3.11e+04
Confirmed Cases   126.1192     29.606      4.260      0.000      63.918     188.320
==============================================================================
Omnibus:                        6.526   Durbin-Watson:                   0.170
Prob(Omnibus):                  0.038   Jarque-Bera (JB):                2.247
Skew:                           0.437   Prob(JB):                        0.325
Kurtosis:                       1.610   Cond. No.                     6.22e+04
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 6.22e+04. This might indicate that there are
strong multicollinearity or other numerical problems.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:                  Gowns   R-squared:                       0.947
Model:                            OLS   Adj. R-squared:                  0.944
Method:                 Least Squares   F-statistic:                     320.4
Date:                Sun, 13 Sep 2020   Prob (F-statistic):           6.48e-13
Time:                        20:58:28   Log-Likelihood:                -193.92
No. Observations:                  20   AIC:                             391.8
Df Residuals:                      18   BIC:                             393.8
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const           -4810.8419   4911.509     -0.980      0.340   -1.51e+04    5507.855
Confirmed Cases     7.4820      0.418     17.900      0.000       6.604       8.360
==============================================================================
Omnibus:                        0.080   Durbin-Watson:                   0.541
Prob(Omnibus):                  0.961   Jarque-Bera (JB):                0.185
Skew:                          -0.123   Prob(JB):                        0.912
Kurtosis:                       2.599   Cond. No.                     6.22e+04
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 6.22e+04. This might indicate that there are
strong multicollinearity or other numerical problems.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:                 Gloves   R-squared:                       0.898
Model:                            OLS   Adj. R-squared:                  0.893
Method:                 Least Squares   F-statistic:                     159.3
Date:                Sun, 13 Sep 2020   Prob (F-statistic):           2.23e-10
Time:                        20:58:28   Log-Likelihood:                -242.58
No. Observations:                  20   AIC:                             489.2
Df Residuals:                      18   BIC:                             491.1
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const            2.764e+05   5.59e+04      4.941      0.000    1.59e+05    3.94e+05
Confirmed Cases    60.0800      4.760     12.622      0.000      50.079      70.081
==============================================================================
Omnibus:                       12.497   Durbin-Watson:                   1.608
Prob(Omnibus):                  0.002   Jarque-Bera (JB):               15.750
Skew:                          -0.926   Prob(JB):                     0.000380
Kurtosis:                       6.934   Cond. No.                     6.22e+04
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 6.22e+04. This might indicate that there are
strong multicollinearity or other numerical problems.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:            Ventilators   R-squared:                       0.768
Model:                            OLS   Adj. R-squared:                  0.755
Method:                 Least Squares   F-statistic:                     59.44
Date:                Sun, 13 Sep 2020   Prob (F-statistic):           4.13e-07
Time:                        20:58:28   Log-Likelihood:                -23.188
No. Observations:                  20   AIC:                             50.38
Df Residuals:                      18   BIC:                             52.37
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const              74.9076      0.963     77.768      0.000      72.884      76.931
Confirmed Cases     0.0006    8.2e-05      7.709      0.000       0.000       0.001
==============================================================================
Omnibus:                        5.370   Durbin-Watson:                   1.251
Prob(Omnibus):                  0.068   Jarque-Bera (JB):                3.069
Skew:                          -0.846   Prob(JB):                        0.216
Kurtosis:                       3.907   Cond. No.                     6.22e+04
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 6.22e+04. This might indicate that there are
strong multicollinearity or other numerical problems.







Western Massachusetts

In [33]:
WM = df.loc[df['Region']=='Western Massachusetts']
WM_CC = WM.dropna()
categories = ['N95s/KN95s', 'Masks', 'Gowns', 'Gloves', 'Ventilators']
for category in categories:
    WM_CC['{} %'.format(category)] = WM_CC[category]/WM_CC[category].iloc[-1] * 100
    
fig, axes = plt.subplots(2, 3, figsize=(25,15))
for ax, category in zip(axes.flatten(), categories):
    sns.distplot(WM_CC[category].diff(), ax=ax)
    ax.set_xlabel(category, fontsize=15)
fig.delaxes(axes[1,2])
WM_CC
Out[33]:
Time Region N95s/KN95s Masks Gowns Gloves Ventilators Confirmed Cases N95s/KN95s % Masks % Gowns % Gloves % Ventilators %
220 2020-04-29 Western Massachusetts 156323.0 300642.0 50128.0 324630.0 60.0 5052.0 12.021684 18.292823 52.217211 53.049232 100.0
227 2020-05-06 Western Massachusetts 196135.0 356892.0 52813.0 366030.0 60.0 5773.0 15.083340 21.715403 55.014115 59.814590 100.0
234 2020-05-13 Western Massachusetts 217121.0 402897.0 58829.0 399030.0 60.0 6526.0 16.697223 24.514617 61.280847 65.207267 100.0
241 2020-05-20 Western Massachusetts 223347.0 435347.0 69279.0 433930.0 60.0 7164.0 17.176020 26.489066 72.166377 70.910431 100.0
248 2020-05-27 Western Massachusetts 259107.0 467597.0 73949.0 467930.0 60.0 7693.0 19.926066 28.451345 77.031011 76.466522 100.0
249 2020-06-03 Western Massachusetts 269912.0 483597.0 74919.0 484930.0 60.0 7982.0 20.757001 29.424879 78.041438 79.244568 100.0
250 2020-06-10 Western Massachusetts 274382.0 493747.0 77299.0 504643.0 60.0 8157.0 21.100757 30.042464 80.520630 82.465957 100.0
251 2020-06-17 Western Massachusetts 274972.0 496797.0 76569.0 499630.0 60.0 8281.0 21.146129 30.228044 79.760206 81.646760 100.0
252 2020-06-24 Western Massachusetts 275262.0 508247.0 83649.0 536043.0 60.0 8394.0 21.168431 30.924729 87.135283 87.597170 100.0
253 2020-07-01 Western Massachusetts 276162.0 512647.0 85099.0 540443.0 60.0 8549.0 21.237644 31.192451 88.645715 88.316194 100.0
254 2020-07-08 Western Massachusetts 276922.0 515447.0 87499.0 547443.0 60.0 8689.0 21.296090 31.362820 91.145741 89.460095 100.0
255 2020-07-15 Western Massachusetts 294047.0 566447.0 88599.0 548443.0 60.0 8844.0 22.613051 34.465959 92.291586 89.623509 100.0
256 2020-07-22 Western Massachusetts 626547.0 908947.0 90399.0 550943.0 60.0 9002.0 48.183247 55.305668 94.166606 90.032046 100.0
257 2020-07-29 Western Massachusetts 1076842.0 1377397.0 91849.0 557183.0 60.0 9207.0 82.812214 83.808915 95.677038 91.051752 100.0
258 2020-08-05 Western Massachusetts 1298047.0 1627297.0 93699.0 574481.0 60.0 9428.0 99.823508 99.014297 97.604142 93.878495 100.0
259 2020-08-12 Western Massachusetts 1298292.0 1630897.0 93699.0 587977.0 60.0 9587.0 99.842349 99.233342 97.604142 96.083936 100.0
260 2020-08-19 Western Massachusetts 1299942.0 1635997.0 93999.0 603241.0 60.0 9759.0 99.969239 99.543656 97.916645 98.578294 100.0
261 2020-08-26 Western Massachusetts 1300342.0 1640997.0 93999.0 603541.0 60.0 9904.0 100.000000 99.847885 97.916645 98.627319 100.0
262 2020-09-02 Western Massachusetts 1300342.0 1641497.0 93999.0 607941.0 60.0 10082.0 100.000000 99.878308 97.916645 99.346342 100.0
263 2020-09-09 Western Massachusetts 1300342.0 1643497.0 95999.0 611941.0 60.0 10212.0 100.000000 100.000000 100.000000 100.000000 100.0
In [34]:
# Confirmed cases vs PPE distribution
fig, axes = plt.subplots(2,1,figsize=(15,14))

percentages = ['N95s/KN95s %', 'Masks %', 'Gowns %', 'Gloves %', 'Ventilators %']

for category in categories:
    axes[0].plot('Time', category, data=WM_CC, marker='.', markersize=10)

axes[0].set_xlabel('Date', fontsize=15)
axes[0].set_ylabel('The Number of PPE Distribution', fontsize=15)
axes[0].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
axes[0].tick_params(direction='out', length=6, width=2, labelsize=10)
axes[0].legend()
axes[0].set_title('PPE Distribution vs Confirmed Cases in WM', fontsize=20)

ax1 = axes[0].twinx()
ax1.plot('Time', 'Confirmed Cases', data=WM_CC, color='y', linestyle='--', linewidth=3, label='Confirmed Cases')

ax1.set_ylabel('Confirmed Cases', fontsize=15)
ax1.tick_params(direction='out', length=6, width=2, labelsize=10)
ax1.legend(loc='upper right')


for percentage in percentages:
    axes[1].plot('Time', percentage, data=WM_CC, marker='.', markersize=10)

axes[1].set_xlabel('Date', fontsize=15)
axes[1].set_ylabel('PPE Distribution %', fontsize=15)
axes[1].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
axes[1].tick_params(direction='out', length=6, width=2, labelsize=10)
axes[1].legend()
axes[1].set_title('PPE Distribution Percentage vs Confirmed Cases in WM', fontsize=20)

ax2 = axes[1].twinx()
ax2.plot('Time', 'Confirmed Cases', data=WM_CC, color='y', linestyle='--', linewidth=3, label='Confirmed Cases')

ax2.set_ylabel('Confirmed Cases', fontsize=15)
ax2.tick_params(direction='out', length=6, width=2, labelsize=10)
ax2.legend(loc='upper right')

plt.show()
In [35]:
pd.set_option("display.max_rows", None, "display.max_columns", None)


# Calculate the ratio of cumulative PPE data to cumulative confirmed cases data (Ratio 1)
for category in categories:
    WM_CC['{} Ratio 1'.format(category)] = WM_CC[category]/WM_CC['Confirmed Cases']
    
    
    
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 2)
# (Interval=2 weeks, one week before + the week itself)
WM_CC['Confirmed Cases(ma1)'] = WM_CC['Confirmed Cases'].rolling(window=2,center=False).mean()
WM_CC.iloc[0,-1] = (3763+5052) / 2
for category in categories:
    WM_CC['{} Ratio 2'.format(category)] = WM_CC[category]/WM_CC['Confirmed Cases(ma1)']





# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 3)
# (Interval=2 weeks, one week after + the week itself)
WM_CC['Confirmed Cases(ma2)'] = WM_CC['Confirmed Cases'].rolling(window=2,center=False).mean().shift(-1)
for category in categories:
    WM_CC['{} Ratio 3'.format(category)] = WM_CC[category]/WM_CC['Confirmed Cases(ma2)']

    
    
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 4)
# (Interval=3 weeks, one week before + one week after + the week itself)
WM_CC['Confirmed Cases(ma3)'] = WM_CC['Confirmed Cases'].rolling(window=3,center=False).mean().shift(-1)
WM_CC.iloc[0,-1] = (3763+5052+5773)/3
for category in categories:
    WM_CC['{} Ratio 4'.format(category)] = WM_CC[category]/WM_CC['Confirmed Cases(ma3)']

    
    
# Calculate the ratio of delta PPE data to delta confirmed cases data (Ratio 5)
for category in categories:
    WM_CC['{} Ratio 5'.format(category)] = WM_CC[category].diff()/WM_CC['Confirmed Cases'].diff()
    
    
    
# Calculate the ratio of delta PPE data to moving average delta confirmed cases data (Ratio 6)
for category in categories:
    WM_CC['{} Ratio 6'.format(category)] = WM_CC[category].diff()/WM_CC['Confirmed Cases'].diff().rolling(window=2,center=False).mean()
WM_CC
Out[35]:
Time Region N95s/KN95s Masks Gowns Gloves Ventilators Confirmed Cases N95s/KN95s % Masks % Gowns % Gloves % Ventilators % N95s/KN95s Ratio 1 Masks Ratio 1 Gowns Ratio 1 Gloves Ratio 1 Ventilators Ratio 1 Confirmed Cases(ma1) N95s/KN95s Ratio 2 Masks Ratio 2 Gowns Ratio 2 Gloves Ratio 2 Ventilators Ratio 2 Confirmed Cases(ma2) N95s/KN95s Ratio 3 Masks Ratio 3 Gowns Ratio 3 Gloves Ratio 3 Ventilators Ratio 3 Confirmed Cases(ma3) N95s/KN95s Ratio 4 Masks Ratio 4 Gowns Ratio 4 Gloves Ratio 4 Ventilators Ratio 4 N95s/KN95s Ratio 5 Masks Ratio 5 Gowns Ratio 5 Gloves Ratio 5 Ventilators Ratio 5 N95s/KN95s Ratio 6 Masks Ratio 6 Gowns Ratio 6 Gloves Ratio 6 Ventilators Ratio 6
220 2020-04-29 Western Massachusetts 156323.0 300642.0 50128.0 324630.0 60.0 5052.0 12.021684 18.292823 52.217211 53.049232 100.0 30.942795 59.509501 9.922407 64.257720 0.011876 4407.5 35.467499 68.211458 11.373341 73.653999 0.013613 5412.5 28.881848 55.545866 9.261524 59.977829 0.011085 4862.666667 32.147587 61.826570 10.308747 66.759665 0.012339 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
227 2020-05-06 Western Massachusetts 196135.0 356892.0 52813.0 366030.0 60.0 5773.0 15.083340 21.715403 55.014115 59.814590 100.0 33.974537 61.820890 9.148276 63.403776 0.010393 5412.5 36.237413 65.938476 9.757598 67.626790 0.011085 6149.5 31.894463 58.035938 8.588178 59.521912 0.009757 5783.666667 33.911878 61.706876 9.131405 63.286842 0.010374 55.217753 78.016644 3.723994 57.420250 0.0 NaN NaN NaN NaN NaN
234 2020-05-13 Western Massachusetts 217121.0 402897.0 58829.0 399030.0 60.0 6526.0 16.697223 24.514617 61.280847 65.207267 100.0 33.270150 61.737205 9.014557 61.144652 0.009194 6149.5 35.307098 65.517034 9.566469 64.888202 0.009757 6845.0 31.719649 58.860044 8.594449 58.295106 0.008766 6487.666667 33.466732 62.101988 9.067821 61.505934 0.009248 27.869854 61.095618 7.989376 43.824701 0.0 28.474898 62.421981 8.162822 44.776119 0.0
241 2020-05-20 Western Massachusetts 223347.0 435347.0 69279.0 433930.0 60.0 7164.0 17.176020 26.489066 72.166377 70.910431 100.0 31.176298 60.768705 9.670436 60.570910 0.008375 6845.0 32.629218 63.600730 10.121110 63.393718 0.008766 7428.5 30.066231 58.604967 9.326109 58.414216 0.008077 7127.666667 31.335220 61.078474 9.719731 60.879671 0.008418 9.758621 50.862069 16.379310 54.702194 0.0 8.951833 46.657081 15.025162 50.179727 0.0
248 2020-05-27 Western Massachusetts 259107.0 467597.0 73949.0 467930.0 60.0 7693.0 19.926066 28.451345 77.031011 76.466522 100.0 33.680879 60.782140 9.612505 60.825426 0.007799 7428.5 34.880124 62.946355 9.954769 62.991183 0.008077 7837.5 33.059904 59.661499 9.435279 59.703987 0.007656 7613.000000 34.034809 61.420859 9.713516 61.464600 0.007881 67.599244 60.964083 8.827977 64.272212 0.0 61.285347 55.269923 8.003428 58.269066 0.0
249 2020-06-03 Western Massachusetts 269912.0 483597.0 74919.0 484930.0 60.0 7982.0 20.757001 29.424879 78.041438 79.244568 100.0 33.815084 60.585943 9.385993 60.752944 0.007517 7837.5 34.438533 61.702967 9.559043 61.873046 0.007656 8069.5 33.448417 59.928992 9.284218 60.094182 0.007435 7944.000000 33.976838 60.875755 9.430891 61.043555 0.007553 37.387543 55.363322 3.356401 58.823529 0.0 26.418093 39.119804 2.371638 41.564792 0.0
250 2020-06-10 Western Massachusetts 274382.0 493747.0 77299.0 504643.0 60.0 8157.0 21.100757 30.042464 80.520630 82.465957 100.0 33.637612 60.530465 9.476401 61.866250 0.007356 8069.5 34.002355 61.186815 9.579156 62.537084 0.007435 8219.0 33.383867 60.073853 9.404915 61.399562 0.007300 8140.000000 33.707862 60.656880 9.496192 61.995455 0.007371 25.542857 58.000000 13.600000 112.645714 0.0 19.267241 43.750000 10.258621 84.969828 0.0
251 2020-06-17 Western Massachusetts 274972.0 496797.0 76569.0 499630.0 60.0 8281.0 21.146129 30.228044 79.760206 81.646760 100.0 33.205168 59.992392 9.246347 60.334501 0.007246 8219.0 33.455652 60.444945 9.316097 60.789634 0.007300 8337.5 32.980150 59.585847 9.183688 59.925637 0.007196 8277.333333 33.219878 60.018967 9.250443 60.361227 0.007249 4.758065 24.596774 -5.887097 -40.427419 0.0 3.946488 20.401338 -4.882943 -33.531773 0.0
252 2020-06-24 Western Massachusetts 275262.0 508247.0 83649.0 536043.0 60.0 8394.0 21.168431 30.924729 87.135283 87.597170 100.0 32.792709 60.548844 9.965332 63.860257 0.007148 8337.5 33.014933 60.959160 10.032864 64.293013 0.007196 8471.5 32.492711 59.994924 9.874166 63.276043 0.007083 8408.000000 32.738107 60.448026 9.948739 63.753925 0.007136 2.566372 101.327434 62.654867 322.238938 0.0 2.447257 96.624473 59.746835 307.282700 0.0
253 2020-07-01 Western Massachusetts 276162.0 512647.0 85099.0 540443.0 60.0 8549.0 21.237644 31.192451 88.645715 88.316194 100.0 32.303427 59.965727 9.954264 63.217101 0.007018 8471.5 32.598949 60.514313 10.045328 63.795432 0.007083 8619.0 32.041072 59.478710 9.873419 62.703678 0.006961 8544.000000 32.322331 60.000819 9.960089 63.254096 0.007022 5.806452 28.387097 9.354839 28.387097 0.0 6.716418 32.835821 10.820896 32.835821 0.0
254 2020-07-08 Western Massachusetts 276922.0 515447.0 87499.0 547443.0 60.0 8689.0 21.296090 31.362820 91.145741 89.460095 100.0 31.870411 59.321786 10.070089 63.004143 0.006905 8619.0 32.129249 59.803574 10.151874 63.515837 0.006961 8766.5 31.588661 58.797354 9.981064 62.447157 0.006844 8694.000000 31.852082 59.287670 10.064297 62.967909 0.006901 5.428571 20.000000 17.142857 50.000000 0.0 5.152542 18.983051 16.271186 47.457627 0.0
255 2020-07-15 Western Massachusetts 294047.0 566447.0 88599.0 548443.0 60.0 8844.0 22.613051 34.465959 92.291586 89.623509 100.0 33.248191 64.048734 10.017978 62.013003 0.006784 8766.5 33.542121 64.614955 10.106542 62.561227 0.006844 8923.0 32.953827 63.481677 9.929284 61.463970 0.006724 8845.000000 33.244432 64.041492 10.016846 62.005992 0.006783 110.483871 329.032258 7.096774 6.451613 0.0 116.101695 345.762712 7.457627 6.779661 0.0
256 2020-07-22 Western Massachusetts 626547.0 908947.0 90399.0 550943.0 60.0 9002.0 48.183247 55.305668 94.166606 90.032046 100.0 69.600866 100.971673 10.042102 61.202288 0.006665 8923.0 70.217079 101.865628 10.131010 61.744144 0.006724 9104.5 68.817288 99.834917 9.929046 60.513263 0.006590 9017.666667 69.479947 100.796252 10.024655 61.095960 0.006654 2104.430380 2167.721519 11.392405 15.822785 0.0 2124.600639 2188.498403 11.501597 15.974441 0.0
257 2020-07-29 Western Massachusetts 1076842.0 1377397.0 91849.0 557183.0 60.0 9207.0 82.812214 83.808915 95.677038 91.051752 100.0 116.959053 149.603237 9.975997 60.517324 0.006517 9104.5 118.275798 151.287495 10.088308 61.198638 0.006590 9317.5 115.571988 147.829031 9.857687 59.799624 0.006439 9212.333333 116.891341 149.516626 9.970221 60.482288 0.006513 2196.560976 2285.121951 7.073171 30.439024 0.0 2480.964187 2580.991736 7.988981 34.380165 0.0
258 2020-08-05 Western Massachusetts 1298047.0 1627297.0 93699.0 574481.0 60.0 9428.0 99.823508 99.014297 97.604142 93.878495 100.0 137.679996 172.602567 9.938375 60.933496 0.006364 9317.5 139.312798 174.649530 10.056238 61.656131 0.006439 9507.5 136.528740 171.159295 9.855272 60.423981 0.006311 9407.333333 137.982460 172.981752 9.960208 61.067359 0.006378 1000.927602 1130.769231 8.371041 78.271493 0.0 1038.521127 1173.239437 8.685446 81.211268 0.0
259 2020-08-12 Western Massachusetts 1298292.0 1630897.0 93699.0 587977.0 60.0 9587.0 99.842349 99.233342 97.604142 96.083936 100.0 135.422134 170.115469 9.773548 61.330656 0.006258 9507.5 136.554510 171.537944 9.855272 61.843492 0.006311 9673.0 134.218133 168.603019 9.686654 60.785382 0.006203 9591.333333 135.360951 170.038611 9.769132 61.302947 0.006256 1.540881 22.641509 0.000000 84.880503 0.0 1.289474 18.947368 0.000000 71.031579 0.0
260 2020-08-19 Western Massachusetts 1299942.0 1635997.0 93999.0 603241.0 60.0 9759.0 99.969239 99.543656 97.916645 98.578294 100.0 133.204427 167.639820 9.632032 61.813813 0.006148 9673.0 134.388711 169.130259 9.717668 62.363383 0.006203 9831.5 132.222143 166.403601 9.561003 61.357982 0.006103 9750.000000 133.327385 167.794564 9.640923 61.870872 0.006154 9.593023 29.651163 1.744186 88.744186 0.0 9.969789 30.815710 1.812689 92.229607 0.0
261 2020-08-26 Western Massachusetts 1300342.0 1640997.0 93999.0 603541.0 60.0 9904.0 100.000000 99.847885 97.916645 98.627319 100.0 131.294628 165.690327 9.491014 60.939116 0.006058 9831.5 132.262829 166.912170 9.561003 61.388496 0.006103 9993.0 130.125288 164.214650 9.406485 60.396377 0.006004 9915.000000 131.148966 165.506505 9.480484 60.871508 0.006051 2.758621 34.482759 0.000000 2.068966 0.0 2.523659 31.545741 0.000000 1.892744 0.0
262 2020-09-02 Western Massachusetts 1300342.0 1641497.0 93999.0 607941.0 60.0 10082.0 100.000000 99.878308 97.916645 99.346342 100.0 128.976592 162.814620 9.323448 60.299643 0.005951 9993.0 130.125288 164.264685 9.406485 60.836686 0.006004 10147.0 128.150389 161.771657 9.263723 59.913373 0.005913 10066.000000 129.181601 163.073415 9.338267 60.395490 0.005961 0.000000 2.808989 0.000000 24.719101 0.0 0.000000 3.095975 0.000000 27.244582 0.0
263 2020-09-09 Western Massachusetts 1300342.0 1643497.0 95999.0 611941.0 60.0 10212.0 100.000000 100.000000 100.000000 100.000000 100.0 127.334704 160.937818 9.400607 59.923717 0.005875 10147.0 128.150389 161.968759 9.460826 60.307579 0.005913 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 0.000000 15.384615 15.384615 30.769231 0.0 0.000000 12.987013 12.987013 25.974026 0.0
In [36]:
# Plot the Ratio of PPE to Confirmed Cases

RATIO1 = []
RATIO2 = []
RATIO3 = []
RATIO4 = []
RATIO5 = []
RATIO6 = []
RATIOS = [RATIO1, RATIO2, RATIO3, RATIO4, RATIO5, RATIO6]
for RATIO in RATIOS:
    for category in categories:
        RATIO.append('{} Ratio {}'.format(category, RATIOS.index(RATIO)+1))

fig, axes = plt.subplots(6,1,figsize=(15,48))
color = ['b', 'g', 'r', 'c', 'm']


for RATIO in RATIOS:
    for category in categories:
        axes[RATIOS.index(RATIO)].plot('Time', category, data=WM_CC, color=color[categories.index(category)], linewidth=3, label=category, marker='.', markersize=12)
        axes[RATIOS.index(RATIO)].set_xlabel('Date', fontsize=15)
        axes[RATIOS.index(RATIO)].set_ylabel('The number of PPE', fontsize=15)
        axes[RATIOS.index(RATIO)].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
        axes[RATIOS.index(RATIO)].legend(loc='best')
        axes[RATIOS.index(RATIO)].set_title('The Ratio of PPE Dstribution to Confirmed Cases in Western Massachusetts', fontsize=20)
    ax1 = axes[RATIOS.index(RATIO)].twinx()
    for ratio in RATIO:
        ax1.plot('Time', ratio, data=WM_CC, color=color[RATIO.index(ratio)], linestyle='--', linewidth=3, label=ratio, marker='^', markersize=8)
        ax1.set_ylabel('Ratio', fontsize=15)
        ax1.legend(loc='best')
plt.show()
In [37]:
for category in categories:
    WM_CC['{} delta'.format(category)] = WM_CC[category].diff()
    WM_CC['Confirmed Cases delta'] = WM_CC['Confirmed Cases'].diff()

fig, axes = plt.subplots(2, 3, figsize=(25,15))

for ax, category in zip(axes.flatten(), categories):
    sns.regplot('Confirmed Cases', category, data=WM_CC, ax=ax)
    ax.set_xlabel('Confirmed Cases', fontsize=15)
    ax.set_ylabel(category, fontsize=15)
fig.delaxes(axes[1,2])
fig.suptitle('Regression Plot (Cumulative vs Cumulative)', fontsize=25)

fig1, axes1 = plt.subplots(2, 3, figsize=(25,15))

for ax, category in zip(axes1.flatten(), categories):
    sns.regplot('Confirmed Cases delta', category + ' delta', data=WM_CC, ax=ax)
    ax.set_xlabel('Confirmed Cases', fontsize=15)
    ax.set_ylabel(category, fontsize=15)
fig1.delaxes(axes1[1,2])
fig1.suptitle('Regression Plot (Delta vs Delta)', fontsize=25)
Out[37]:
Text(0.5, 0.98, 'Regression Plot (Delta vs Delta)')
In [38]:
import statsmodels.api as sm
Y = [pd.DataFrame] * 5
X = [pd.DataFrame] * 5
for category in categories:
    Y[categories.index(category)] = WM_CC[category]
    X[categories.index(category)] = WM_CC['Confirmed Cases']
    X[categories.index(category)] = sm.add_constant(X[categories.index(category)])
    model = sm.OLS(Y[categories.index(category)], X[categories.index(category)])
    results = model.fit()
    print(results.summary())
                            OLS Regression Results                            
==============================================================================
Dep. Variable:             N95s/KN95s   R-squared:                       0.608
Model:                            OLS   Adj. R-squared:                  0.586
Method:                 Least Squares   F-statistic:                     27.87
Date:                Sun, 13 Sep 2020   Prob (F-statistic):           5.10e-05
Time:                        20:58:36   Log-Likelihood:                -280.74
No. Observations:                  20   AIC:                             565.5
Df Residuals:                      18   BIC:                             567.5
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const           -1.672e+06   4.41e+05     -3.792      0.001    -2.6e+06   -7.46e+05
Confirmed Cases   272.9084     51.697      5.279      0.000     164.296     381.520
==============================================================================
Omnibus:                       10.218   Durbin-Watson:                   0.211
Prob(Omnibus):                  0.006   Jarque-Bera (JB):                2.062
Skew:                          -0.066   Prob(JB):                        0.357
Kurtosis:                       1.433   Cond. No.                     5.28e+04
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 5.28e+04. This might indicate that there are
strong multicollinearity or other numerical problems.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:                  Masks   R-squared:                       0.647
Model:                            OLS   Adj. R-squared:                  0.627
Method:                 Least Squares   F-statistic:                     32.97
Date:                Sun, 13 Sep 2020   Prob (F-statistic):           1.92e-05
Time:                        20:58:36   Log-Likelihood:                -281.98
No. Observations:                  20   AIC:                             568.0
Df Residuals:                      18   BIC:                             570.0
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const           -1.776e+06   4.69e+05     -3.785      0.001   -2.76e+06    -7.9e+05
Confirmed Cases   315.8850     55.015      5.742      0.000     200.303     431.467
==============================================================================
Omnibus:                       10.665   Durbin-Watson:                   0.203
Prob(Omnibus):                  0.005   Jarque-Bera (JB):                2.092
Skew:                          -0.056   Prob(JB):                        0.351
Kurtosis:                       1.420   Cond. No.                     5.28e+04
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 5.28e+04. This might indicate that there are
strong multicollinearity or other numerical problems.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:                  Gowns   R-squared:                       0.967
Model:                            OLS   Adj. R-squared:                  0.965
Method:                 Least Squares   F-statistic:                     521.6
Date:                Sun, 13 Sep 2020   Prob (F-statistic):           9.63e-15
Time:                        20:58:36   Log-Likelihood:                -185.20
No. Observations:                  20   AIC:                             374.4
Df Residuals:                      18   BIC:                             376.4
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const           -2380.7629   3713.191     -0.641      0.529   -1.02e+04    5420.361
Confirmed Cases     9.9467      0.436     22.839      0.000       9.032      10.862
==============================================================================
Omnibus:                        8.528   Durbin-Watson:                   0.733
Prob(Omnibus):                  0.014   Jarque-Bera (JB):                1.954
Skew:                          -0.122   Prob(JB):                        0.376
Kurtosis:                       1.488   Cond. No.                     5.28e+04
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 5.28e+04. This might indicate that there are
strong multicollinearity or other numerical problems.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:                 Gloves   R-squared:                       0.988
Model:                            OLS   Adj. R-squared:                  0.988
Method:                 Least Squares   F-statistic:                     1525.
Date:                Sun, 13 Sep 2020   Prob (F-statistic):           7.44e-19
Time:                        20:58:36   Log-Likelihood:                -209.86
No. Observations:                  20   AIC:                             423.7
Df Residuals:                      18   BIC:                             425.7
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const            2.637e+04   1.27e+04      2.069      0.053    -404.457    5.31e+04
Confirmed Cases    58.3715      1.494     39.058      0.000      55.232      61.511
==============================================================================
Omnibus:                        2.125   Durbin-Watson:                   1.057
Prob(Omnibus):                  0.346   Jarque-Bera (JB):                1.706
Skew:                           0.676   Prob(JB):                        0.426
Kurtosis:                       2.532   Cond. No.                     5.28e+04
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 5.28e+04. This might indicate that there are
strong multicollinearity or other numerical problems.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:            Ventilators   R-squared:                        -inf
Model:                            OLS   Adj. R-squared:                   -inf
Method:                 Least Squares   F-statistic:                    -18.00
Date:                Sun, 13 Sep 2020   Prob (F-statistic):               1.00
Time:                        20:58:36   Log-Likelihood:                 601.21
No. Observations:                  20   AIC:                            -1198.
Df Residuals:                      18   BIC:                            -1196.
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const              60.0000   3.11e-14   1.93e+15      0.000      60.000      60.000
Confirmed Cases  8.674e-19   3.65e-18      0.238      0.815    -6.8e-18    8.54e-18
==============================================================================
Omnibus:                      466.626   Durbin-Watson:                   0.000
Prob(Omnibus):                  0.000   Jarque-Bera (JB):                7.500
Skew:                           0.000   Prob(JB):                       0.0235
Kurtosis:                       0.000   Cond. No.                     5.28e+04
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 5.28e+04. This might indicate that there are
strong multicollinearity or other numerical problems.







Massachusetts

In [39]:
MA_CC = df.loc[df['Region']=='Massachusetts'].dropna()
categories = ['N95s/KN95s', 'Masks', 'Gowns', 'Gloves', 'Ventilators']
for category in categories:
    MA_CC['{} %'.format(category)] = MA_CC[category]/MA_CC[category].iloc[-1] * 100
    
# fig, axes = plt.subplots(2, 3, figsize=(25,15))
# for ax, category in zip(axes.flatten(), categories):
#     sns.distplot(MA_CC[category].diff(), ax=ax)
#     ax.set_xlabel(category, fontsize=15)
# fig.delaxes(axes[1,2])
MA_CC
Out[39]:
Time Region N95s/KN95s Masks Gowns Gloves Ventilators Confirmed Cases N95s/KN95s % Masks % Gowns % Gloves % Ventilators %
308 2020-04-29 Massachusetts 990826.0 1863412.0 285795.0 3987284.0 675.0 60265.0 8.841171 14.851105 37.799222 37.806528 99.410898
315 2020-05-06 Massachusetts 1246197.0 2290427.0 340057.0 5273534.0 675.0 72025.0 11.119854 18.254349 44.975909 50.002461 99.410898
322 2020-05-13 Massachusetts 1385499.0 2744148.0 411454.0 6083122.0 675.0 80497.0 12.362850 21.870435 54.418870 57.678791 99.410898
329 2020-05-20 Massachusetts 1481001.0 2951030.0 476763.0 6643694.0 675.0 88970.0 13.215017 23.519253 63.056632 62.994009 99.410898
336 2020-05-27 Massachusetts 1713615.0 3154780.0 576570.0 7097694.0 679.0 94220.0 15.290639 25.143109 76.257097 67.298734 100.000000
337 2020-06-03 Massachusetts 1784126.0 3290580.0 608770.0 7618366.0 679.0 97964.0 15.919811 26.225414 80.515867 72.235629 100.000000
338 2020-06-10 Massachusetts 2544530.0 3469230.0 638660.0 7888596.0 679.0 100158.0 22.704919 27.649226 84.469115 74.797889 100.000000
339 2020-06-17 Massachusetts 2556595.0 3434680.0 647490.0 7839666.0 679.0 101654.0 22.812575 27.373868 85.636970 74.333946 100.000000
340 2020-06-24 Massachusetts 4388525.0 3538480.0 666890.0 8271946.0 679.0 102762.0 39.158942 28.201138 88.202813 78.432727 100.000000
341 2020-07-01 Massachusetts 4409365.0 4007230.0 678510.0 8867546.0 679.0 103858.0 39.344898 31.937003 89.739673 84.080072 100.000000
342 2020-07-08 Massachusetts 4437140.0 4041230.0 691495.0 8922946.0 679.0 104961.0 39.592735 32.207978 91.457068 84.605362 100.000000
343 2020-07-15 Massachusetts 4530795.0 4689430.0 705322.0 9469546.0 679.0 106128.0 40.428421 37.374032 93.285826 89.788100 100.000000
344 2020-07-22 Massachusetts 7447255.0 6733830.0 714422.0 9590446.0 679.0 107413.0 66.452083 53.667583 94.489391 90.934447 100.000000
345 2020-07-29 Massachusetts 8923945.0 10001695.0 726012.0 9906079.0 679.0 109096.0 79.628632 79.711962 96.022283 93.927208 100.000000
346 2020-08-05 Massachusetts 9292070.0 10451295.0 734962.0 9971377.0 679.0 111371.0 82.913423 83.295204 97.206009 94.546349 100.000000
347 2020-08-12 Massachusetts 10476785.0 11665045.0 736612.0 10116833.0 679.0 113198.0 93.484671 92.968604 97.424238 95.925530 100.000000
348 2020-08-19 Massachusetts 11161755.0 12488545.0 742512.0 10422377.0 679.0 115048.0 99.596679 99.531772 98.204572 98.822629 100.000000
349 2020-08-26 Massachusetts 11192185.0 12525245.0 747887.0 10502349.0 679.0 117085.0 99.868207 99.824265 98.915469 99.580906 100.000000
350 2020-09-02 Massachusetts 11194995.0 12544695.0 752587.0 10527949.0 679.0 119426.0 99.893281 99.979278 99.537090 99.823639 100.000000
351 2020-09-09 Massachusetts 11206955.0 12547295.0 756087.0 10546549.0 679.0 121396.0 100.000000 100.000000 100.000000 100.000000 100.000000
In [40]:
# Confirmed cases vs PPE distribution
fig, axes = plt.subplots(2,1,figsize=(15,14))

percentages = ['N95s/KN95s %', 'Masks %', 'Gowns %', 'Gloves %', 'Ventilators %']

for category in categories:
    axes[0].plot('Time', category, data=MA_CC, marker='.', markersize=10)

axes[0].set_xlabel('Date', fontsize=15)
axes[0].set_ylabel('The Number of PPE Distribution', fontsize=15)
axes[0].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
axes[0].tick_params(direction='out', length=6, width=2, labelsize=10)
axes[0].legend()
axes[0].set_title('PPE Distribution vs Confirmed Cases in MA', fontsize=20)

ax1 = axes[0].twinx()
ax1.plot('Time', 'Confirmed Cases', data=MA_CC, color='y', linestyle='--', linewidth=3, label='Confirmed Cases')

ax1.set_ylabel('Confirmed Cases', fontsize=15)
ax1.tick_params(direction='out', length=6, width=2, labelsize=10)
ax1.legend(loc='upper right')


for percentage in percentages:
    axes[1].plot('Time', percentage, data=MA_CC, marker='.', markersize=10)

axes[1].set_xlabel('Date', fontsize=15)
axes[1].set_ylabel('PPE Distribution %', fontsize=15)
axes[1].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
axes[1].tick_params(direction='out', length=6, width=2, labelsize=10)
axes[1].legend()
axes[1].set_title('PPE Distribution Percentage vs Confirmed Cases in MA', fontsize=20)

ax2 = axes[1].twinx()
ax2.plot('Time', 'Confirmed Cases', data=MA_CC, color='y', linestyle='--', linewidth=3, label='Confirmed Cases')

ax2.set_ylabel('Confirmed Cases', fontsize=15)
ax2.tick_params(direction='out', length=6, width=2, labelsize=10)
ax2.legend(loc='upper right')

plt.show()
In [41]:
pd.set_option("display.max_rows", None, "display.max_columns", None)


# Calculate the ratio of cumulative PPE data to cumulative confirmed cases data (Ratio 1)
for category in categories:
    MA_CC['{} Ratio 1'.format(category)] = MA_CC[category]/MA_CC['Confirmed Cases']
    
    
    
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 2)
# (Interval=2 weeks, one week before + the week itself)
MA_CC['Confirmed Cases(ma1)'] = MA_CC['Confirmed Cases'].rolling(window=2,center=False).mean()
MA_CC.iloc[0,-1] = (42944+60265) / 2
for category in categories:
    MA_CC['{} Ratio 2'.format(category)] = MA_CC[category]/MA_CC['Confirmed Cases(ma1)']





# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 3)
# (Interval=2 weeks, one week after + the week itself)
MA_CC['Confirmed Cases(ma2)'] = MA_CC['Confirmed Cases'].rolling(window=2,center=False).mean().shift(-1)
for category in categories:
    MA_CC['{} Ratio 3'.format(category)] = MA_CC[category]/MA_CC['Confirmed Cases(ma2)']

    
    
# Calculate the ratio of cumulative PPE data to moving average of cumulative confirmed cases data (Ratio 4)
# (Interval=3 weeks, one week before + one week after + the week itself)
MA_CC['Confirmed Cases(ma3)'] = MA_CC['Confirmed Cases'].rolling(window=3,center=False).mean().shift(-1)
MA_CC.iloc[0,-1] = (42944+60265+72025)/3
for category in categories:
    MA_CC['{} Ratio 4'.format(category)] = MA_CC[category]/MA_CC['Confirmed Cases(ma3)']

    
    
# Calculate the ratio of delta PPE data to delta confirmed cases data (Ratio 5)
for category in categories:
    MA_CC['{} Ratio 5'.format(category)] = MA_CC[category].diff()/MA_CC['Confirmed Cases'].diff()
    
    
    
# Calculate the ratio of delta PPE data to moving average delta confirmed cases data (Ratio 6)
for category in categories:
    MA_CC['{} Ratio 6'.format(category)] = MA_CC[category].diff()/MA_CC['Confirmed Cases'].diff().rolling(window=2,center=False).mean()
MA_CC
Out[41]:
Time Region N95s/KN95s Masks Gowns Gloves Ventilators Confirmed Cases N95s/KN95s % Masks % Gowns % Gloves % Ventilators % N95s/KN95s Ratio 1 Masks Ratio 1 Gowns Ratio 1 Gloves Ratio 1 Ventilators Ratio 1 Confirmed Cases(ma1) N95s/KN95s Ratio 2 Masks Ratio 2 Gowns Ratio 2 Gloves Ratio 2 Ventilators Ratio 2 Confirmed Cases(ma2) N95s/KN95s Ratio 3 Masks Ratio 3 Gowns Ratio 3 Gloves Ratio 3 Ventilators Ratio 3 Confirmed Cases(ma3) N95s/KN95s Ratio 4 Masks Ratio 4 Gowns Ratio 4 Gloves Ratio 4 Ventilators Ratio 4 N95s/KN95s Ratio 5 Masks Ratio 5 Gowns Ratio 5 Gloves Ratio 5 Ventilators Ratio 5 N95s/KN95s Ratio 6 Masks Ratio 6 Gowns Ratio 6 Gloves Ratio 6 Ventilators Ratio 6
308 2020-04-29 Massachusetts 990826.0 1863412.0 285795.0 3987284.0 675.0 60265.0 8.841171 14.851105 37.799222 37.806528 99.410898 16.441152 30.920302 4.742305 66.162516 0.011201 51604.5 19.200380 36.109487 5.538180 77.266207 0.013080 66145.0 14.979605 28.171623 4.320735 60.280959 0.010205 58411.333333 16.962907 31.901549 4.892800 68.262164 0.011556 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
315 2020-05-06 Massachusetts 1246197.0 2290427.0 340057.0 5273534.0 675.0 72025.0 11.119854 18.254349 44.975909 50.002461 99.410898 17.302284 31.800444 4.721375 73.218105 0.009372 66145.0 18.840381 34.627364 5.141084 79.726873 0.010205 76261.0 16.341210 30.034054 4.459121 69.151126 0.008851 70929.000000 17.569640 32.291827 4.794330 74.349476 0.009517 21.715221 36.310799 4.614116 109.375000 0.000000 NaN NaN NaN NaN NaN
322 2020-05-13 Massachusetts 1385499.0 2744148.0 411454.0 6083122.0 675.0 80497.0 12.362850 21.870435 54.418870 57.678791 99.410898 17.211809 34.090065 5.111420 75.569549 0.008385 76261.0 18.167858 35.983635 5.395340 79.767142 0.008851 84733.5 16.351254 32.385633 4.855860 71.791228 0.007966 80497.333333 17.211738 34.089924 5.111399 75.569236 0.008385 16.442635 53.555359 8.427408 95.560434 0.000000 13.770463 44.851819 7.057829 80.030447 0.000000
329 2020-05-20 Massachusetts 1481001.0 2951030.0 476763.0 6643694.0 675.0 88970.0 13.215017 23.519253 63.056632 62.994009 99.410898 16.646072 33.168821 5.358694 74.673418 0.007587 84733.5 17.478341 34.827193 5.626618 78.406935 0.007966 91595.0 16.169016 32.218243 5.205120 72.533370 0.007369 87895.666667 16.849534 33.574238 5.424192 75.586138 0.007680 11.271332 24.416617 7.707896 66.159802 0.000000 11.271998 24.418058 7.708351 66.163706 0.000000
336 2020-05-27 Massachusetts 1713615.0 3154780.0 576570.0 7097694.0 679.0 94220.0 15.290639 25.143109 76.257097 67.298734 100.000000 18.187381 33.483125 6.119401 75.331076 0.007207 91595.0 18.708609 34.442710 6.294776 77.489972 0.007413 96092.0 17.833066 32.830829 6.000187 73.863527 0.007066 93718.000000 18.284801 33.662477 6.152180 75.734587 0.007245 44.307429 38.809524 19.010857 86.476190 0.000762 33.901334 29.694673 14.545945 66.166290 0.000583
337 2020-06-03 Massachusetts 1784126.0 3290580.0 608770.0 7618366.0 679.0 97964.0 15.919811 26.225414 80.515867 72.235629 100.000000 18.212057 33.589686 6.214222 77.766996 0.006931 96092.0 18.566853 34.244058 6.335283 79.282001 0.007066 99061.0 18.010377 33.217714 6.145405 76.905806 0.006854 97447.333333 18.308618 33.767779 6.247169 78.179317 0.006968 18.833066 36.271368 8.600427 139.068376 0.000000 15.679564 30.197910 7.160329 115.782077 0.000000
338 2020-06-10 Massachusetts 2544530.0 3469230.0 638660.0 7888596.0 679.0 100158.0 22.704919 27.649226 84.469115 74.797889 100.000000 25.405160 34.637573 6.376525 78.761517 0.006779 99061.0 25.686496 35.021149 6.447139 79.633721 0.006854 100906.0 25.216835 34.380810 6.329257 78.177670 0.006729 99925.333333 25.464313 34.718223 6.391372 78.944906 0.006795 346.583409 81.426618 13.623519 123.167730 0.000000 256.114517 60.171775 10.067363 91.017178 0.000000
339 2020-06-17 Massachusetts 2556595.0 3434680.0 647490.0 7839666.0 679.0 101654.0 22.812575 27.373868 85.636970 74.333946 100.000000 25.149970 33.787947 6.369548 77.121077 0.006680 100906.0 25.336402 34.038412 6.416764 77.692764 0.006729 102208.0 25.013649 33.604806 6.335023 76.703057 0.006643 101524.666667 25.182008 33.830990 6.377662 77.219323 0.006688 8.064840 -23.094920 5.902406 -32.707219 0.000000 6.539295 -18.726287 4.785908 -26.520325 0.000000
340 2020-06-24 Massachusetts 4388525.0 3538480.0 666890.0 8271946.0 679.0 102762.0 39.158942 28.201138 88.202813 78.432727 100.000000 42.705718 34.433740 6.489656 80.496156 0.006608 102208.0 42.937197 34.620382 6.524832 80.932471 0.006643 103310.0 42.479189 34.251089 6.455232 80.069170 0.006572 102758.000000 42.707380 34.435080 6.489908 80.499290 0.006608 1653.366426 93.682310 17.509025 390.144404 0.000000 1407.012289 79.723502 14.900154 332.012289 0.000000
341 2020-07-01 Massachusetts 4409365.0 4007230.0 678510.0 8867546.0 679.0 103858.0 39.344898 31.937003 89.739673 84.080072 100.000000 42.455709 38.583739 6.533055 85.381444 0.006538 103310.0 42.680912 38.788404 6.567709 85.834343 0.006572 104409.5 42.231454 38.379937 6.498547 84.930452 0.006503 103860.333333 42.454755 38.582873 6.532908 85.379526 0.006538 19.014599 427.691606 10.602190 543.430657 0.000000 18.911071 425.362976 10.544465 540.471869 0.000000
342 2020-07-08 Massachusetts 4437140.0 4041230.0 691495.0 8922946.0 679.0 104961.0 39.592735 32.207978 91.457068 84.605362 100.000000 42.274178 38.502206 6.588114 85.012014 0.006469 104409.5 42.497474 38.705578 6.622913 85.461055 0.006503 105544.5 42.040466 38.289347 6.551691 84.542027 0.006433 104982.333333 42.265588 38.494382 6.586775 84.994739 0.006468 25.181324 30.825023 11.772439 50.226655 0.000000 25.261482 30.923147 11.809914 50.386539 0.000000
343 2020-07-15 Massachusetts 4530795.0 4689430.0 705322.0 9469546.0 679.0 106128.0 40.428421 37.374032 93.285826 89.788100 100.000000 42.691797 44.186548 6.645956 89.227593 0.006398 105544.5 42.927817 44.430832 6.682698 89.720886 0.006433 106770.5 42.434895 43.920652 6.605963 88.690659 0.006359 106167.333333 42.675980 44.170178 6.643494 89.194536 0.006396 80.252785 555.441302 11.848329 468.380463 0.000000 82.515419 571.101322 12.182379 481.585903 0.000000
344 2020-07-22 Massachusetts 7447255.0 6733830.0 714422.0 9590446.0 679.0 107413.0 66.452083 53.667583 94.489391 90.934447 100.000000 69.332902 62.691015 6.651169 89.285710 0.006321 106770.5 69.750118 63.068263 6.691193 89.822994 0.006359 108254.5 68.793953 62.203696 6.599467 88.591661 0.006272 107545.666667 69.247374 62.613680 6.642964 89.175569 0.006314 2269.618677 1590.972763 7.081712 94.085603 0.000000 2378.841762 1667.536705 7.422512 98.613377 0.000000
345 2020-07-29 Massachusetts 8923945.0 10001695.0 726012.0 9906079.0 679.0 109096.0 79.628632 79.711962 96.022283 93.927208 100.000000 81.799012 91.677926 6.654799 90.801487 0.006224 108254.5 82.434864 92.390570 6.706530 91.507318 0.006272 110233.5 80.954927 90.731901 6.586129 89.864506 0.006160 109293.333333 81.651321 91.512398 6.642784 90.637541 0.006213 877.415330 1941.690434 6.886512 187.541889 0.000000 995.074124 2202.065364 7.809973 212.690701 0.000000
346 2020-08-05 Massachusetts 9292070.0 10451295.0 734962.0 9971377.0 679.0 111371.0 82.913423 83.295204 97.206009 94.546349 100.000000 83.433479 93.842158 6.599222 89.532975 0.006097 110233.5 84.294430 94.810516 6.667320 90.456867 0.006160 112284.5 82.754699 93.078697 6.545534 88.804572 0.006047 111221.666667 83.545502 93.968157 6.608083 89.653188 0.006105 161.813187 197.626374 3.934066 28.702418 0.000000 186.015664 227.185447 4.522486 32.995452 0.000000
347 2020-08-12 Massachusetts 10476785.0 11665045.0 736612.0 10116833.0 679.0 113198.0 93.484671 92.968604 97.424238 95.925530 100.000000 92.552739 103.049921 6.507288 89.372895 0.005998 112284.5 93.305710 103.888293 6.560229 90.099996 0.006047 114123.0 91.802573 102.214672 6.454545 88.648502 0.005950 113205.666667 92.546471 103.042942 6.506847 89.366843 0.005998 648.448276 664.340449 0.903120 79.614669 0.000000 577.627986 591.784495 0.804486 70.919551 0.000000
348 2020-08-19 Massachusetts 11161755.0 12488545.0 742512.0 10422377.0 679.0 115048.0 99.596679 99.531772 98.204572 98.822629 100.000000 97.018245 108.550735 6.453932 90.591553 0.005902 114123.0 97.804606 109.430571 6.506243 91.325824 0.005950 116066.5 96.166896 107.598187 6.397298 89.796599 0.005850 115110.333333 96.965708 108.491954 6.450437 90.542497 0.005899 370.254054 445.135135 3.189189 165.158919 0.000000 372.570030 447.919500 3.209138 166.192004 0.000000
349 2020-08-26 Massachusetts 11192185.0 12525245.0 747887.0 10502349.0 679.0 117085.0 99.868207 99.824265 98.915469 99.580906 100.000000 95.590255 106.975659 6.387556 89.698501 0.005799 116066.5 96.429073 107.914385 6.443608 90.485618 0.005850 118255.5 94.644097 105.916807 6.324332 88.810660 0.005742 117186.333333 95.507596 106.883155 6.382033 89.620937 0.005794 14.938635 18.016691 2.638684 39.259696 0.000000 15.657319 18.883458 2.765629 41.148444 0.000000
350 2020-09-02 Massachusetts 11194995.0 12544695.0 752587.0 10527949.0 679.0 119426.0 99.893281 99.979278 99.537090 99.823639 100.000000 93.740015 105.041574 6.301701 88.154581 0.005686 118255.5 94.667859 106.081282 6.364076 89.027140 0.005742 120411.0 92.973192 104.182301 6.250152 87.433449 0.005639 119302.333333 93.837184 105.150458 6.308234 88.245961 0.005691 1.200342 8.308415 2.007689 10.935498 0.000000 1.283691 8.885336 2.147099 11.694838 0.000000
351 2020-09-09 Massachusetts 11206955.0 12547295.0 756087.0 10546549.0 679.0 121396.0 100.000000 100.000000 100.000000 100.000000 100.000000 92.317333 103.358389 6.228269 86.877236 0.005593 120411.0 93.072518 104.203893 6.279219 87.587920 0.005639 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 6.071066 1.319797 1.776650 9.441624 0.000000 5.548597 1.206217 1.623753 8.629088 0.000000
In [42]:
# Plot the Ratio of PPE to Confirmed Cases

RATIO1 = []
RATIO2 = []
RATIO3 = []
RATIO4 = []
RATIO5 = []
RATIO6 = []
RATIOS = [RATIO1, RATIO2, RATIO3, RATIO4, RATIO5, RATIO6]
for RATIO in RATIOS:
    for category in categories:
        RATIO.append('{} Ratio {}'.format(category, RATIOS.index(RATIO)+1))

fig, axes = plt.subplots(6,1,figsize=(15,48))
color = ['b', 'g', 'r', 'c', 'm']


for RATIO in RATIOS:
    for category in categories:
        axes[RATIOS.index(RATIO)].plot('Time', category, data=MA_CC, color=color[categories.index(category)], linewidth=3, label=category, marker='.', markersize=12)
        axes[RATIOS.index(RATIO)].set_xlabel('Date', fontsize=15)
        axes[RATIOS.index(RATIO)].set_ylabel('The number of PPE', fontsize=15)
        axes[RATIOS.index(RATIO)].set_xlim([datetime.date(2020, 4, 29), datetime.date(2020,9,9)])
        axes[RATIOS.index(RATIO)].legend(loc='best')
        axes[RATIOS.index(RATIO)].set_title('The Ratio of PPE Dstribution to Confirmed Cases in Massachusetts', fontsize=20)
    ax1 = axes[RATIOS.index(RATIO)].twinx()
    for ratio in RATIO:
        ax1.plot('Time', ratio, data=MA_CC, color=color[RATIO.index(ratio)], linestyle='--', linewidth=3, label=ratio, marker='^', markersize=8)
        ax1.set_ylabel('Ratio', fontsize=15)
        ax1.legend(loc='best')
plt.show()
In [43]:
for category in categories:
    MA_CC['{} delta'.format(category)] = MA_CC[category].diff()
    MA_CC['Confirmed Cases delta'] = MA_CC['Confirmed Cases'].diff()

fig, axes = plt.subplots(2, 3, figsize=(25,15))

for ax, category in zip(axes.flatten(), categories):
    sns.regplot('Confirmed Cases', category, data=MA_CC, ax=ax)
    ax.set_xlabel('Confirmed Cases', fontsize=15)
    ax.set_ylabel(category, fontsize=15)
fig.delaxes(axes[1,2])
fig.suptitle('Regression Plot (Cumulative vs Cumulative)', fontsize=25)

fig1, axes1 = plt.subplots(2, 3, figsize=(25,15))

for ax, category in zip(axes1.flatten(), categories):
    sns.regplot('Confirmed Cases delta', category + ' delta', data=MA_CC, ax=ax)
    ax.set_xlabel('Confirmed Cases', fontsize=15)
    ax.set_ylabel(category, fontsize=15)
fig1.delaxes(axes1[1,2])
fig1.suptitle('Regression Plot (Delta vs Delta)', fontsize=25)
Out[43]:
Text(0.5, 0.98, 'Regression Plot (Delta vs Delta)')
In [44]:
import statsmodels.api as sm
Y = [pd.DataFrame] * 5
X = [pd.DataFrame] * 5
for category in categories:
    Y[categories.index(category)] = MA_CC[category]
    X[categories.index(category)] = MA_CC['Confirmed Cases']
    X[categories.index(category)] = sm.add_constant(X[categories.index(category)])
    model = sm.OLS(Y[categories.index(category)], X[categories.index(category)])
    results = model.fit()
    print(results.summary())
                            OLS Regression Results                            
==============================================================================
Dep. Variable:             N95s/KN95s   R-squared:                       0.683
Model:                            OLS   Adj. R-squared:                  0.665
Method:                 Least Squares   F-statistic:                     38.74
Date:                Sun, 13 Sep 2020   Prob (F-statistic):           7.15e-06
Time:                        20:58:41   Log-Likelihood:                -320.47
No. Observations:                  20   AIC:                             644.9
Df Residuals:                      18   BIC:                             646.9
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const           -1.563e+07   3.45e+06     -4.526      0.000   -2.29e+07   -8.38e+06
Confirmed Cases   209.6131     33.679      6.224      0.000     138.855     280.371
==============================================================================
Omnibus:                        6.226   Durbin-Watson:                   0.248
Prob(Omnibus):                  0.044   Jarque-Bera (JB):                1.685
Skew:                           0.026   Prob(JB):                        0.431
Kurtosis:                       1.579   Cond. No.                     6.83e+05
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 6.83e+05. This might indicate that there are
strong multicollinearity or other numerical problems.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:                  Masks   R-squared:                       0.616
Model:                            OLS   Adj. R-squared:                  0.595
Method:                 Least Squares   F-statistic:                     28.89
Date:                Sun, 13 Sep 2020   Prob (F-statistic):           4.16e-05
Time:                        20:58:41   Log-Likelihood:                -323.15
No. Observations:                  20   AIC:                             650.3
Df Residuals:                      18   BIC:                             652.3
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const           -1.456e+07   3.95e+06     -3.688      0.002   -2.29e+07   -6.27e+06
Confirmed Cases   207.0086     38.515      5.375      0.000     126.091     287.926
==============================================================================
Omnibus:                       13.542   Durbin-Watson:                   0.181
Prob(Omnibus):                  0.001   Jarque-Bera (JB):                2.274
Skew:                           0.025   Prob(JB):                        0.321
Kurtosis:                       1.349   Cond. No.                     6.83e+05
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 6.83e+05. This might indicate that there are
strong multicollinearity or other numerical problems.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:                  Gowns   R-squared:                       0.962
Model:                            OLS   Adj. R-squared:                  0.959
Method:                 Least Squares   F-statistic:                     450.9
Date:                Sun, 13 Sep 2020   Prob (F-statistic):           3.42e-14
Time:                        20:58:41   Log-Likelihood:                -232.63
No. Observations:                  20   AIC:                             469.3
Df Residuals:                      18   BIC:                             471.3
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const           -2.655e+05   4.27e+04     -6.212      0.000   -3.55e+05   -1.76e+05
Confirmed Cases     8.8531      0.417     21.235      0.000       7.977       9.729
==============================================================================
Omnibus:                        3.706   Durbin-Watson:                   0.455
Prob(Omnibus):                  0.157   Jarque-Bera (JB):                2.332
Skew:                          -0.637   Prob(JB):                        0.312
Kurtosis:                       1.916   Cond. No.                     6.83e+05
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 6.83e+05. This might indicate that there are
strong multicollinearity or other numerical problems.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:                 Gloves   R-squared:                       0.962
Model:                            OLS   Adj. R-squared:                  0.960
Method:                 Least Squares   F-statistic:                     452.8
Date:                Sun, 13 Sep 2020   Prob (F-statistic):           3.30e-14
Time:                        20:58:41   Log-Likelihood:                -284.41
No. Observations:                  20   AIC:                             572.8
Df Residuals:                      18   BIC:                             574.8
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const           -3.499e+06   5.69e+05     -6.146      0.000   -4.69e+06    -2.3e+06
Confirmed Cases   118.1383      5.552     21.279      0.000     106.474     129.803
==============================================================================
Omnibus:                        4.606   Durbin-Watson:                   0.384
Prob(Omnibus):                  0.100   Jarque-Bera (JB):                1.791
Skew:                          -0.344   Prob(JB):                        0.408
Kurtosis:                       1.705   Cond. No.                     6.83e+05
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 6.83e+05. This might indicate that there are
strong multicollinearity or other numerical problems.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:            Ventilators   R-squared:                       0.709
Model:                            OLS   Adj. R-squared:                  0.693
Method:                 Least Squares   F-statistic:                     43.80
Date:                Sun, 13 Sep 2020   Prob (F-statistic):           3.26e-06
Time:                        20:58:41   Log-Likelihood:                -25.443
No. Observations:                  20   AIC:                             54.89
Df Residuals:                      18   BIC:                             56.88
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
const             669.3351      1.355    494.033      0.000     666.489     672.181
Confirmed Cases  8.745e-05   1.32e-05      6.618      0.000    5.97e-05       0.000
==============================================================================
Omnibus:                        1.915   Durbin-Watson:                   1.014
Prob(Omnibus):                  0.384   Jarque-Bera (JB):                1.205
Skew:                          -0.599   Prob(JB):                        0.547
Kurtosis:                       2.889   Cond. No.                     6.83e+05
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 6.83e+05. This might indicate that there are
strong multicollinearity or other numerical problems.